-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
lib,permission: ignore internalModuleStat on module loading #55797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||
| require('./required-module'); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||
| import './required-module.mjs'; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||
| console.log('ok'); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||
| console.log('ok'); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| 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/); | ||
| } |
This comment was marked as abuse.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.