-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
src: add permission support to config file #60746
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
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
marco-ippolito:permission-config
Nov 18, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| const { spawnSync } = require('child_process'); | ||
| spawnSync(process.execPath, ['--version']); |
This file contains hidden or 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,6 @@ | ||
| { | ||
| "permission": { | ||
| "allow-addons": true, | ||
| "allow-wasi": true | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| { | ||
| "permission": { | ||
| "allow-child-process": true, | ||
| "allow-worker": true | ||
| } | ||
| } |
This file contains hidden or 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,10 @@ | ||
| { | ||
| "permission": { | ||
| "allow-fs-read": [ | ||
| "*" | ||
| ], | ||
| "allow-fs-write": [ | ||
| "*" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| { | ||
| "permission": { | ||
| "allow-net": true, | ||
| "allow-inspector": true | ||
| } | ||
| } |
This file contains hidden or 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('fs').readFileSync(__filename); |
This file contains hidden or 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,6 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const os = require('os'); | ||
|
|
||
| const tmpFile = path.join(os.tmpdir(), 'permission-test-' + Date.now() + '.txt'); | ||
| fs.writeFileSync(tmpFile, 'test'); |
This file contains hidden or 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,107 @@ | ||
| import { spawnPromisified } from '../common/index.mjs'; | ||
| import * as fixtures from '../common/fixtures.mjs'; | ||
| import assert from 'node:assert'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| describe('Permission model config file support', () => { | ||
| it('should load filesystem read/write permissions from config file', async () => { | ||
| const configPath = fixtures.path('permission/config-fs-read-write.json'); | ||
| const readTestPath = fixtures.path('permission/fs-read-test.js'); | ||
| const writeTestPath = fixtures.path('permission/fs-write-test.js'); | ||
|
|
||
| { | ||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| readTestPath, | ||
| ]); | ||
| assert.strictEqual(result.code, 0); | ||
marco-ippolito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| { | ||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| writeTestPath, | ||
| ]); | ||
| assert.strictEqual(result.code, 0); | ||
| } | ||
| }); | ||
|
|
||
| it('should load child process and worker permissions from config file', async () => { | ||
| const configPath = fixtures.path('permission/config-child-worker.json'); | ||
| const childTestPath = fixtures.path('permission/child-process-test.js'); | ||
|
|
||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| '--allow-fs-read=*', | ||
| childTestPath, | ||
| ]); | ||
| assert.strictEqual(result.code, 0); | ||
| }); | ||
|
|
||
| it('should load network and inspector permissions from config file', async () => { | ||
| const configPath = fixtures.path('permission/config-net-inspector.json'); | ||
|
|
||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| '--allow-fs-read=*', | ||
| '-p', | ||
| 'process.permission.has("net") && process.permission.has("inspector")', | ||
| ]); | ||
| assert.match(result.stdout, /true/); | ||
| assert.strictEqual(result.code, 0); | ||
| }); | ||
|
|
||
| it('should load addons and wasi permissions from config file', async () => { | ||
| const configPath = fixtures.path('permission/config-addons-wasi.json'); | ||
|
|
||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| '--allow-fs-read=*', | ||
| '-p', | ||
| 'process.permission.has("addon") && process.permission.has("wasi")', | ||
| ]); | ||
| assert.match(result.stdout, /true/); | ||
| assert.strictEqual(result.code, 0); | ||
| }); | ||
|
|
||
| it('should deny operations when permissions are not in config file', async () => { | ||
| const configPath = fixtures.path('permission/config-fs-read-write.json'); | ||
|
|
||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| '--allow-fs-read=*', | ||
| '-p', | ||
| 'process.permission.has("child")', | ||
| ]); | ||
| assert.match(result.stdout, /false/); | ||
| assert.strictEqual(result.code, 0); | ||
| }); | ||
|
|
||
| it('should combine config file permissions with CLI flags', async () => { | ||
| const configPath = fixtures.path('permission/config-fs-read-write.json'); | ||
|
|
||
| const result = await spawnPromisified(process.execPath, [ | ||
| '--permission', | ||
| '--experimental-config-file', | ||
| configPath, | ||
| '--allow-child-process', | ||
| '--allow-fs-read=*', | ||
| '-p', | ||
| 'process.permission.has("child") && process.permission.has("fs.read")', | ||
| ]); | ||
| assert.match(result.stdout, /true/); | ||
| assert.strictEqual(result.code, 0); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we enable
--permissionby default if the "permission" object exists in the config-file? So users won't need to pass--permission.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the behaviour of the already present flags it should work out of the box! 🚀
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its would be an improvement we can do it in a followup, that also might require us to review the flags we support. For example
--testis not supported in the config file but--watchis (I think its just a discrepancy). We have to standardize the behavior