@@ -11,6 +11,7 @@ const regularFolder = process.env.ALLOWEDFOLDER;
1111const regularFile = process . env . ALLOWEDFILE ;
1212const blockedFolder = process . env . BLOCKEDFOLDER ;
1313const blockedFile = process . env . BLOCKEDFILE ;
14+ const bufferBlockedFile = Buffer . from ( process . env . BLOCKEDFILE ) ;
1415const blockedFileURL = require ( 'url' ) . pathToFileURL ( process . env . BLOCKEDFILE ) ;
1516const relativeProtectedFile = process . env . RELATIVEBLOCKEDFILE ;
1617const relativeProtectedFolder = process . env . RELATIVEBLOCKEDFOLDER ;
@@ -34,6 +35,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
3435 permission : 'FileSystemWrite' ,
3536 resource : path . toNamespacedPath ( blockedFile ) ,
3637 } ) ) ;
38+ fs . writeFile ( bufferBlockedFile , 'example' , common . expectsError ( {
39+ code : 'ERR_ACCESS_DENIED' ,
40+ permission : 'FileSystemWrite' ,
41+ resource : path . toNamespacedPath ( blockedFile ) ,
42+ } ) ) ;
3743 assert . throws ( ( ) => {
3844 fs . writeFileSync ( blockedFileURL , 'example' ) ;
3945 } , {
@@ -102,6 +108,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
102108 permission : 'FileSystemWrite' ,
103109 resource : path . toNamespacedPath ( blockedFile ) ,
104110 } ) ;
111+ assert . throws ( ( ) => {
112+ fs . utimes ( bufferBlockedFile , new Date ( ) , new Date ( ) , ( ) => { } ) ;
113+ } , {
114+ code : 'ERR_ACCESS_DENIED' ,
115+ permission : 'FileSystemWrite' ,
116+ resource : path . toNamespacedPath ( blockedFile ) ,
117+ } ) ;
105118 assert . throws ( ( ) => {
106119 fs . utimes ( blockedFileURL , new Date ( ) , new Date ( ) , ( ) => { } ) ;
107120 } , {
@@ -135,6 +148,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
135148 permission : 'FileSystemWrite' ,
136149 resource : path . toNamespacedPath ( blockedFile ) ,
137150 } ) ;
151+ assert . throws ( ( ) => {
152+ fs . lutimes ( bufferBlockedFile , new Date ( ) , new Date ( ) , ( ) => { } ) ;
153+ } , {
154+ code : 'ERR_ACCESS_DENIED' ,
155+ permission : 'FileSystemWrite' ,
156+ resource : path . toNamespacedPath ( blockedFile ) ,
157+ } ) ;
138158 assert . throws ( ( ) => {
139159 fs . lutimes ( blockedFileURL , new Date ( ) , new Date ( ) , ( ) => { } ) ;
140160 } , {
@@ -193,6 +213,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
193213 permission : 'FileSystemWrite' ,
194214 resource : path . toNamespacedPath ( blockedFile ) ,
195215 } ) ) ;
216+ fs . rename ( bufferBlockedFile , path . join ( blockedFile , 'renamed' ) , common . expectsError ( {
217+ code : 'ERR_ACCESS_DENIED' ,
218+ permission : 'FileSystemWrite' ,
219+ resource : path . toNamespacedPath ( blockedFile ) ,
220+ } ) ) ;
196221 assert . throws ( ( ) => {
197222 fs . renameSync ( blockedFileURL , path . join ( blockedFile , 'renamed' ) ) ;
198223 } , {
@@ -245,6 +270,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
245270 permission : 'FileSystemWrite' ,
246271 resource : path . toNamespacedPath ( path . join ( relativeProtectedFolder , 'any-file' ) ) ,
247272 } ) ) ;
273+ fs . copyFile ( bufferBlockedFile , path . join ( relativeProtectedFolder , 'any-file' ) , common . expectsError ( {
274+ code : 'ERR_ACCESS_DENIED' ,
275+ permission : 'FileSystemWrite' ,
276+ resource : path . toNamespacedPath ( path . join ( relativeProtectedFolder , 'any-file' ) ) ,
277+ } ) ) ;
248278}
249279
250280// fs.cp
@@ -295,6 +325,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
295325 code : 'ERR_ACCESS_DENIED' ,
296326 permission : 'FileSystemWrite' ,
297327 } ) ) ;
328+ fs . open ( bufferBlockedFile , fs . constants . O_RDWR | 0x10000000 , common . expectsError ( {
329+ code : 'ERR_ACCESS_DENIED' ,
330+ permission : 'FileSystemWrite' ,
331+ } ) ) ;
298332 assert . rejects ( async ( ) => {
299333 await fs . promises . open ( blockedFile , fs . constants . O_RDWR | fs . constants . O_NOFOLLOW ) ;
300334 } , {
@@ -322,6 +356,12 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
322356 code : 'ERR_ACCESS_DENIED' ,
323357 permission : 'FileSystemWrite' ,
324358 } ) ;
359+ assert . throws ( ( ) => {
360+ fs . chmod ( bufferBlockedFile , 0o755 , common . mustNotCall ( ) ) ;
361+ } , {
362+ code : 'ERR_ACCESS_DENIED' ,
363+ permission : 'FileSystemWrite' ,
364+ } ) ;
325365 assert . throws ( ( ) => {
326366 fs . chmod ( blockedFileURL , 0o755 , common . mustNotCall ( ) ) ;
327367 } , {
@@ -358,6 +398,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
358398 code : 'ERR_ACCESS_DENIED' ,
359399 permission : 'FileSystemWrite' ,
360400 } ) ) ;
401+ fs . appendFile ( bufferBlockedFile , 'new data' , common . expectsError ( {
402+ code : 'ERR_ACCESS_DENIED' ,
403+ permission : 'FileSystemWrite' ,
404+ } ) ) ;
361405 assert . throws ( ( ) => {
362406 fs . appendFileSync ( blockedFileURL , 'new data' ) ;
363407 } , {
@@ -378,6 +422,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
378422 code : 'ERR_ACCESS_DENIED' ,
379423 permission : 'FileSystemWrite' ,
380424 } ) ) ;
425+ fs . chown ( bufferBlockedFile , 1541 , 999 , common . expectsError ( {
426+ code : 'ERR_ACCESS_DENIED' ,
427+ permission : 'FileSystemWrite' ,
428+ } ) ) ;
381429 assert . throws ( ( ) => {
382430 fs . chownSync ( blockedFileURL , 1541 , 999 ) ;
383431 } , {
@@ -399,6 +447,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
399447 code : 'ERR_ACCESS_DENIED' ,
400448 permission : 'FileSystemWrite' ,
401449 } ) ) ;
450+ fs . lchown ( bufferBlockedFile , 1541 , 999 , common . expectsError ( {
451+ code : 'ERR_ACCESS_DENIED' ,
452+ permission : 'FileSystemWrite' ,
453+ } ) ) ;
402454 assert . throws ( ( ) => {
403455 fs . lchownSync ( blockedFileURL , 1541 , 999 ) ;
404456 } , {
@@ -426,6 +478,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
426478 code : 'ERR_ACCESS_DENIED' ,
427479 permission : 'FileSystemWrite' ,
428480 } ) ) ;
481+ fs . link ( bufferBlockedFile , path . join ( blockedFolder , '/linked' ) , common . expectsError ( {
482+ code : 'ERR_ACCESS_DENIED' ,
483+ permission : 'FileSystemWrite' ,
484+ } ) ) ;
429485 assert . throws ( ( ) => {
430486 fs . linkSync ( blockedFileURL , path . join ( blockedFolder , '/linked' ) ) ;
431487 } , {
@@ -450,6 +506,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
450506 permission : 'FileSystemWrite' ,
451507 resource : path . toNamespacedPath ( blockedFile ) ,
452508 } ) ;
509+ assert . throws ( ( ) => {
510+ fs . unlinkSync ( bufferBlockedFile ) ;
511+ } , {
512+ code : 'ERR_ACCESS_DENIED' ,
513+ permission : 'FileSystemWrite' ,
514+ resource : path . toNamespacedPath ( blockedFile ) ,
515+ } ) ;
453516 fs . unlink ( blockedFile , common . expectsError ( {
454517 code : 'ERR_ACCESS_DENIED' ,
455518 permission : 'FileSystemWrite' ,
0 commit comments