@@ -492,24 +492,7 @@ using the [`--allow-child-process`][] and [`--allow-worker`][] respectively.
492
492
493
493
When enabling the Permission Model through the [ ` --experimental-permission ` ] [ ]
494
494
flag a new property ` permission ` is added to the ` process ` object.
495
- This property contains two functions:
496
-
497
- ##### ` permission.deny(scope [,parameters]) `
498
-
499
- API call to deny permissions at runtime ([ ` permission.deny() ` ] [ ] )
500
-
501
- ``` js
502
- process .permission .deny (' fs' ); // Deny permissions to ALL fs operations
503
-
504
- // Deny permissions to ALL FileSystemWrite operations
505
- process .permission .deny (' fs.write' );
506
- // deny FileSystemWrite permissions to the protected-folder
507
- process .permission .deny (' fs.write' , [' /home/rafaelgss/protected-folder' ]);
508
- // Deny permissions to ALL FileSystemRead operations
509
- process .permission .deny (' fs.read' );
510
- // deny FileSystemRead permissions to the protected-folder
511
- process .permission .deny (' fs.read' , [' /home/rafaelgss/protected-folder' ]);
512
- ```
495
+ This property contains one function:
513
496
514
497
##### ` permission.has(scope ,parameters) `
515
498
@@ -519,10 +502,8 @@ API call to check permissions at runtime ([`permission.has()`][])
519
502
process .permission .has (' fs.write' ); // true
520
503
process .permission .has (' fs.write' , ' /home/rafaelgss/protected-folder' ); // true
521
504
522
- process .permission .deny (' fs.write' , ' /home/rafaelgss/protected-folder' );
523
-
524
- process .permission .has (' fs.write' ); // true
525
- process .permission .has (' fs.write' , ' /home/rafaelgss/protected-folder' ); // false
505
+ process .permission .has (' fs.read' ); // true
506
+ process .permission .has (' fs.read' , ' /home/rafaelgss/protected-folder' ); // false
526
507
```
527
508
528
509
#### File System Permissions
@@ -560,39 +541,18 @@ There are constraints you need to know before using this system:
560
541
561
542
* Native modules are restricted by default when using the Permission Model.
562
543
* Relative paths are not supported through the CLI (` --allow-fs-* ` ).
563
- The runtime API supports relative paths.
564
544
* The model does not inherit to a child node process.
565
545
* The model does not inherit to a worker thread.
566
546
* When creating symlinks the target (first argument) should have read and
567
547
write access.
568
548
* Permission changes are not retroactively applied to existing resources.
569
- Consider the following snippet:
570
- ``` js
571
- const fs = require (' node:fs' );
572
-
573
- // Open a fd
574
- const fd = fs .openSync (' ./README.md' , ' r' );
575
- // Then, deny access to all fs.read operations
576
- process .permission .deny (' fs.read' );
577
- // This call will NOT fail and the file will be read
578
- const data = fs .readFileSync (fd);
579
- ```
580
-
581
- Therefore, when possible, apply the permissions rules before any statement:
582
-
583
- ``` js
584
- process .permission .deny (' fs.read' );
585
- const fd = fs .openSync (' ./README.md' , ' r' );
586
- // Error: Access to this API has been restricted
587
- ```
588
549
589
550
[ Security Policy ] : https://github.com/nodejs/node/blob/main/SECURITY.md
590
551
[ `--allow-child-process` ] : cli.md#--allow-child-process
591
552
[ `--allow-fs-read` ] : cli.md#--allow-fs-read
592
553
[ `--allow-fs-write` ] : cli.md#--allow-fs-write
593
554
[ `--allow-worker` ] : cli.md#--allow-worker
594
555
[ `--experimental-permission` ] : cli.md#--experimental-permission
595
- [ `permission.deny()` ] : process.md#processpermissiondenyscope-reference
596
556
[ `permission.has()` ] : process.md#processpermissionhasscope-reference
597
557
[ import maps ] : https://url.spec.whatwg.org/#relative-url-with-fragment-string
598
558
[ relative-url string ] : https://url.spec.whatwg.org/#relative-url-with-fragment-string
0 commit comments