-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permission: ignore internalModuleStat on module loading
This improves Permission Model usage when allowing read access to specifi modules. To achieve that, the permission model check on internalModuleStat has been removed meaning that on module loading, uv_fs_stat is performed on files and folders even when the permission model is enabled. Although a uv_fs_stat is performed, reading/executing the module will still pass by the permission model check. Without this PR when an app tries to --allow-fs-read=./a.js --allow-fs-read=./b.js where `a` attempt to load b, it will fails as it reads $pwd and no permission has been given to this path. PR-URL: #55797 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Ulises Gascón <[email protected]>
- Loading branch information
Showing
11 changed files
with
93 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./required-module'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './required-module.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('ok'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('ok'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Flags: --experimental-permission --allow-fs-read=* --allow-child-process | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
common.skipIfWorker(); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const assert = require('node:assert'); | ||
const { spawnSync } = require('node:child_process'); | ||
|
||
{ | ||
const mainModule = fixtures.path('permission', 'main-module.js'); | ||
const requiredModule = fixtures.path('permission', 'required-module.js'); | ||
const { status, stdout, stderr } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-permission', | ||
'--allow-fs-read', mainModule, | ||
'--allow-fs-read', requiredModule, | ||
mainModule, | ||
] | ||
); | ||
|
||
assert.strictEqual(status, 0, stderr.toString()); | ||
assert.strictEqual(stdout.toString(), 'ok\n'); | ||
} | ||
|
||
{ | ||
// When required module is not passed as allowed path | ||
const mainModule = fixtures.path('permission', 'main-module.js'); | ||
const { status, stderr } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-permission', | ||
'--allow-fs-read', mainModule, | ||
mainModule, | ||
] | ||
); | ||
|
||
assert.strictEqual(status, 1, stderr.toString()); | ||
assert.match(stderr.toString(), /Error: Access to this API has been restricted/); | ||
} | ||
|
||
{ | ||
// ESM loader test | ||
const mainModule = fixtures.path('permission', 'main-module.mjs'); | ||
const requiredModule = fixtures.path('permission', 'required-module.mjs'); | ||
const { status, stdout, stderr } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-permission', | ||
'--allow-fs-read', mainModule, | ||
'--allow-fs-read', requiredModule, | ||
mainModule, | ||
] | ||
); | ||
|
||
assert.strictEqual(status, 0, stderr.toString()); | ||
assert.strictEqual(stdout.toString(), 'ok\n'); | ||
} | ||
|
||
{ | ||
// When required module is not passed as allowed path (ESM) | ||
const mainModule = fixtures.path('permission', 'main-module.mjs'); | ||
const { status, stderr } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-permission', | ||
'--allow-fs-read', mainModule, | ||
mainModule, | ||
] | ||
); | ||
|
||
assert.strictEqual(status, 1, stderr.toString()); | ||
assert.match(stderr.toString(), /Error: Access to this API has been restricted/); | ||
} |