File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
fixtures/permission/loader Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -423,7 +423,7 @@ function readPackageScope(checkPath) {
423423 checkPath = StringPrototypeSlice ( checkPath , 0 , separatorIndex ) ;
424424 // Stop the search when the process doesn't have permissions
425425 // to walk upwards
426- if ( enabledPermission && ! permission . has ( 'fs.read' , checkPath ) ) {
426+ if ( enabledPermission && ! permission . has ( 'fs.read' , checkPath + sep ) ) {
427427 return false ;
428428 }
429429 if ( StringPrototypeEndsWith ( checkPath , sep + 'node_modules' ) )
Original file line number Diff line number Diff line change 1+ const fs = require ( 'node:fs' ) ;
2+
3+ fs . readFile ( '/etc/passwd' , ( ) => { } ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- require ( '../common' ) ;
3+ const common = require ( '../common' ) ;
4+
5+ const fixtures = require ( '../common/fixtures' ) ;
46const { spawnSync } = require ( 'child_process' ) ;
57const assert = require ( 'assert' ) ;
68const fs = require ( 'fs' ) ;
9+ const path = require ( 'path' ) ;
710
811{
912 const { status, stdout } = spawnSync (
@@ -126,3 +129,21 @@ const fs = require('fs');
126129 assert . strictEqual ( status , 1 ) ;
127130 assert . ok ( ! fs . existsSync ( 'permission-deny-example.md' ) ) ;
128131}
132+
133+ {
134+ const firstPath = path . sep + process . cwd ( ) . split ( path . sep , 2 ) [ 1 ] ;
135+ if ( firstPath . startsWith ( '/etc' ) ) {
136+ common . skip ( '/etc as firstPath' ) ;
137+ }
138+ const file = fixtures . path ( 'permission' , 'loader' , 'index.js' ) ;
139+ const { status, stderr } = spawnSync (
140+ process . execPath ,
141+ [
142+ '--experimental-permission' ,
143+ `--allow-fs-read=${ firstPath } ` ,
144+ file ,
145+ ]
146+ ) ;
147+ assert . match ( stderr . toString ( ) , / r e s o u r c e : \s + ' \/ e t c \/ p a s s w d ' / ) ;
148+ assert . strictEqual ( status , 1 ) ;
149+ }
You can’t perform that action at this time.
0 commit comments