@@ -11,6 +11,7 @@ const regularFolder = process.env.ALLOWEDFOLDER;
11
11
const regularFile = process . env . ALLOWEDFILE ;
12
12
const blockedFolder = process . env . BLOCKEDFOLDER ;
13
13
const blockedFile = process . env . BLOCKEDFILE ;
14
+ const bufferBlockedFile = Buffer . from ( process . env . BLOCKEDFILE ) ;
14
15
const blockedFileURL = require ( 'url' ) . pathToFileURL ( process . env . BLOCKEDFILE ) ;
15
16
const relativeProtectedFile = process . env . RELATIVEBLOCKEDFILE ;
16
17
const relativeProtectedFolder = process . env . RELATIVEBLOCKEDFOLDER ;
@@ -34,6 +35,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
34
35
permission : 'FileSystemWrite' ,
35
36
resource : path . toNamespacedPath ( blockedFile ) ,
36
37
} ) ) ;
38
+ fs . writeFile ( bufferBlockedFile , 'example' , common . expectsError ( {
39
+ code : 'ERR_ACCESS_DENIED' ,
40
+ permission : 'FileSystemWrite' ,
41
+ resource : path . toNamespacedPath ( blockedFile ) ,
42
+ } ) ) ;
37
43
assert . throws ( ( ) => {
38
44
fs . writeFileSync ( blockedFileURL , 'example' ) ;
39
45
} , {
@@ -102,6 +108,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
102
108
permission : 'FileSystemWrite' ,
103
109
resource : path . toNamespacedPath ( blockedFile ) ,
104
110
} ) ;
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
+ } ) ;
105
118
assert . throws ( ( ) => {
106
119
fs . utimes ( blockedFileURL , new Date ( ) , new Date ( ) , ( ) => { } ) ;
107
120
} , {
@@ -135,6 +148,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
135
148
permission : 'FileSystemWrite' ,
136
149
resource : path . toNamespacedPath ( blockedFile ) ,
137
150
} ) ;
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
+ } ) ;
138
158
assert . throws ( ( ) => {
139
159
fs . lutimes ( blockedFileURL , new Date ( ) , new Date ( ) , ( ) => { } ) ;
140
160
} , {
@@ -193,6 +213,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
193
213
permission : 'FileSystemWrite' ,
194
214
resource : path . toNamespacedPath ( blockedFile ) ,
195
215
} ) ) ;
216
+ fs . rename ( bufferBlockedFile , path . join ( blockedFile , 'renamed' ) , common . expectsError ( {
217
+ code : 'ERR_ACCESS_DENIED' ,
218
+ permission : 'FileSystemWrite' ,
219
+ resource : path . toNamespacedPath ( blockedFile ) ,
220
+ } ) ) ;
196
221
assert . throws ( ( ) => {
197
222
fs . renameSync ( blockedFileURL , path . join ( blockedFile , 'renamed' ) ) ;
198
223
} , {
@@ -245,6 +270,11 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
245
270
permission : 'FileSystemWrite' ,
246
271
resource : path . toNamespacedPath ( path . join ( relativeProtectedFolder , 'any-file' ) ) ,
247
272
} ) ) ;
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
+ } ) ) ;
248
278
}
249
279
250
280
// fs.cp
@@ -295,6 +325,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
295
325
code : 'ERR_ACCESS_DENIED' ,
296
326
permission : 'FileSystemWrite' ,
297
327
} ) ) ;
328
+ fs . open ( bufferBlockedFile , fs . constants . O_RDWR | 0x10000000 , common . expectsError ( {
329
+ code : 'ERR_ACCESS_DENIED' ,
330
+ permission : 'FileSystemWrite' ,
331
+ } ) ) ;
298
332
assert . rejects ( async ( ) => {
299
333
await fs . promises . open ( blockedFile , fs . constants . O_RDWR | fs . constants . O_NOFOLLOW ) ;
300
334
} , {
@@ -322,6 +356,12 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
322
356
code : 'ERR_ACCESS_DENIED' ,
323
357
permission : 'FileSystemWrite' ,
324
358
} ) ;
359
+ assert . throws ( ( ) => {
360
+ fs . chmod ( bufferBlockedFile , 0o755 , common . mustNotCall ( ) ) ;
361
+ } , {
362
+ code : 'ERR_ACCESS_DENIED' ,
363
+ permission : 'FileSystemWrite' ,
364
+ } ) ;
325
365
assert . throws ( ( ) => {
326
366
fs . chmod ( blockedFileURL , 0o755 , common . mustNotCall ( ) ) ;
327
367
} , {
@@ -358,6 +398,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
358
398
code : 'ERR_ACCESS_DENIED' ,
359
399
permission : 'FileSystemWrite' ,
360
400
} ) ) ;
401
+ fs . appendFile ( bufferBlockedFile , 'new data' , common . expectsError ( {
402
+ code : 'ERR_ACCESS_DENIED' ,
403
+ permission : 'FileSystemWrite' ,
404
+ } ) ) ;
361
405
assert . throws ( ( ) => {
362
406
fs . appendFileSync ( blockedFileURL , 'new data' ) ;
363
407
} , {
@@ -378,6 +422,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
378
422
code : 'ERR_ACCESS_DENIED' ,
379
423
permission : 'FileSystemWrite' ,
380
424
} ) ) ;
425
+ fs . chown ( bufferBlockedFile , 1541 , 999 , common . expectsError ( {
426
+ code : 'ERR_ACCESS_DENIED' ,
427
+ permission : 'FileSystemWrite' ,
428
+ } ) ) ;
381
429
assert . throws ( ( ) => {
382
430
fs . chownSync ( blockedFileURL , 1541 , 999 ) ;
383
431
} , {
@@ -399,6 +447,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
399
447
code : 'ERR_ACCESS_DENIED' ,
400
448
permission : 'FileSystemWrite' ,
401
449
} ) ) ;
450
+ fs . lchown ( bufferBlockedFile , 1541 , 999 , common . expectsError ( {
451
+ code : 'ERR_ACCESS_DENIED' ,
452
+ permission : 'FileSystemWrite' ,
453
+ } ) ) ;
402
454
assert . throws ( ( ) => {
403
455
fs . lchownSync ( blockedFileURL , 1541 , 999 ) ;
404
456
} , {
@@ -426,6 +478,10 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
426
478
code : 'ERR_ACCESS_DENIED' ,
427
479
permission : 'FileSystemWrite' ,
428
480
} ) ) ;
481
+ fs . link ( bufferBlockedFile , path . join ( blockedFolder , '/linked' ) , common . expectsError ( {
482
+ code : 'ERR_ACCESS_DENIED' ,
483
+ permission : 'FileSystemWrite' ,
484
+ } ) ) ;
429
485
assert . throws ( ( ) => {
430
486
fs . linkSync ( blockedFileURL , path . join ( blockedFolder , '/linked' ) ) ;
431
487
} , {
@@ -450,6 +506,13 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
450
506
permission : 'FileSystemWrite' ,
451
507
resource : path . toNamespacedPath ( blockedFile ) ,
452
508
} ) ;
509
+ assert . throws ( ( ) => {
510
+ fs . unlinkSync ( bufferBlockedFile ) ;
511
+ } , {
512
+ code : 'ERR_ACCESS_DENIED' ,
513
+ permission : 'FileSystemWrite' ,
514
+ resource : path . toNamespacedPath ( blockedFile ) ,
515
+ } ) ;
453
516
fs . unlink ( blockedFile , common . expectsError ( {
454
517
code : 'ERR_ACCESS_DENIED' ,
455
518
permission : 'FileSystemWrite' ,
0 commit comments