@@ -62,7 +62,6 @@ const {
6262} = constants ;
6363
6464const pathModule = require ( 'path' ) ;
65- const { isAbsolute } = pathModule ;
6665const { isArrayBufferView } = require ( 'internal/util/types' ) ;
6766
6867const binding = internalBinding ( 'fs' ) ;
@@ -1801,18 +1800,12 @@ function symlink(target, path, type, callback) {
18011800 validateOneOf ( type , 'type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
18021801 }
18031802
1804- if ( permission . isEnabled ( ) ) {
1805- // The permission model's security guarantees fall apart in the presence of
1806- // relative symbolic links. Thus, we have to prevent their creation.
1807- if ( BufferIsBuffer ( target ) ) {
1808- if ( ! isAbsolute ( BufferToString ( target ) ) ) {
1809- callback ( new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ) ;
1810- return ;
1811- }
1812- } else if ( typeof target !== 'string' || ! isAbsolute ( toPathIfFileURL ( target ) ) ) {
1813- callback ( new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ) ;
1814- return ;
1815- }
1803+ // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass
1804+ // the permission model security guarantees. Thus, this API is disabled unless fs.read
1805+ // and fs.write permission has been given.
1806+ if ( permission . isEnabled ( ) && ! permission . has ( 'fs' ) ) {
1807+ callback ( new ERR_ACCESS_DENIED ( 'fs.symlink API requires full fs.read and fs.write permissions.' ) ) ;
1808+ return ;
18161809 }
18171810
18181811 target = getValidatedPath ( target , 'target' ) ;
@@ -1876,16 +1869,11 @@ function symlinkSync(target, path, type) {
18761869 }
18771870 }
18781871
1879- if ( permission . isEnabled ( ) ) {
1880- // The permission model's security guarantees fall apart in the presence of
1881- // relative symbolic links. Thus, we have to prevent their creation.
1882- if ( BufferIsBuffer ( target ) ) {
1883- if ( ! isAbsolute ( BufferToString ( target ) ) ) {
1884- throw new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ;
1885- }
1886- } else if ( typeof target !== 'string' || ! isAbsolute ( toPathIfFileURL ( target ) ) ) {
1887- throw new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ;
1888- }
1872+ // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass
1873+ // the permission model security guarantees. Thus, this API is disabled unless fs.read
1874+ // and fs.write permission has been given.
1875+ if ( permission . isEnabled ( ) && ! permission . has ( 'fs' ) ) {
1876+ throw new ERR_ACCESS_DENIED ( 'fs.symlink API requires full fs.read and fs.write permissions.' ) ;
18891877 }
18901878
18911879 target = getValidatedPath ( target , 'target' ) ;
0 commit comments