@@ -60,7 +60,6 @@ const {
6060} = constants ;
6161
6262const pathModule = require ( 'path' ) ;
63- const { isAbsolute } = pathModule ;
6463const { isArrayBufferView } = require ( 'internal/util/types' ) ;
6564
6665const binding = internalBinding ( 'fs' ) ;
@@ -1778,18 +1777,12 @@ function symlink(target, path, type, callback) {
17781777 validateOneOf ( type , 'type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
17791778 }
17801779
1781- if ( permission . isEnabled ( ) ) {
1782- // The permission model's security guarantees fall apart in the presence of
1783- // relative symbolic links. Thus, we have to prevent their creation.
1784- if ( BufferIsBuffer ( target ) ) {
1785- if ( ! isAbsolute ( BufferToString ( target ) ) ) {
1786- callback ( new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ) ;
1787- return ;
1788- }
1789- } else if ( typeof target !== 'string' || ! isAbsolute ( toPathIfFileURL ( target ) ) ) {
1790- callback ( new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ) ;
1791- return ;
1792- }
1780+ // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass
1781+ // the permission model security guarantees. Thus, this API is disabled unless fs.read
1782+ // and fs.write permission has been given.
1783+ if ( permission . isEnabled ( ) && ! permission . has ( 'fs' ) ) {
1784+ callback ( new ERR_ACCESS_DENIED ( 'fs.symlink API requires full fs.read and fs.write permissions.' ) ) ;
1785+ return ;
17931786 }
17941787
17951788 target = getValidatedPath ( target , 'target' ) ;
@@ -1853,16 +1846,11 @@ function symlinkSync(target, path, type) {
18531846 }
18541847 }
18551848
1856- if ( permission . isEnabled ( ) ) {
1857- // The permission model's security guarantees fall apart in the presence of
1858- // relative symbolic links. Thus, we have to prevent their creation.
1859- if ( BufferIsBuffer ( target ) ) {
1860- if ( ! isAbsolute ( BufferToString ( target ) ) ) {
1861- throw new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ;
1862- }
1863- } else if ( typeof target !== 'string' || ! isAbsolute ( toPathIfFileURL ( target ) ) ) {
1864- throw new ERR_ACCESS_DENIED ( 'relative symbolic link target' ) ;
1865- }
1849+ // Due to the nature of Node.js runtime, symlinks has different edge cases that can bypass
1850+ // the permission model security guarantees. Thus, this API is disabled unless fs.read
1851+ // and fs.write permission has been given.
1852+ if ( permission . isEnabled ( ) && ! permission . has ( 'fs' ) ) {
1853+ throw new ERR_ACCESS_DENIED ( 'fs.symlink API requires full fs.read and fs.write permissions.' ) ;
18661854 }
18671855
18681856 target = getValidatedPath ( target , 'target' ) ;
0 commit comments