Skip to content

Commit 77600e4

Browse files
committed
src,permission: do not grant cwd read access without entrypoint
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent dd9777b commit 77600e4

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/env.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,8 @@ Environment::Environment(IsolateData* isolate_data,
11691169
}
11701170
}
11711171

1172-
if (first_argv != "inspect") {
1172+
if (!first_argv.empty() && first_argv != "-" &&
1173+
first_argv != "inspect") {
11731174
options_->allow_fs_read.push_back(first_argv);
11741175
}
11751176
}

‎test/parallel/test-permission-fs-read-entrypoint.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if (!common.hasCrypto) {
1414

1515
const assert = require('assert');
1616
const fixtures = require('../common/fixtures');
17+
const tmpdir = require('../common/tmpdir');
1718
const { spawnSync } = require('child_process');
1819

1920
const file = fixtures.path('permission', 'hello-world.js');
@@ -36,3 +37,19 @@ const fsReadLoader = fixtures.path('permission', 'fs-read-loader.js');
3637
);
3738
assert.strictEqual(status, 0, `${arg0} Error: ${stderr.toString()}`);
3839
});
40+
41+
// When the code is read from stdin there is no entrypoint, so no implicit
42+
// read access should be granted (in particular, not to the cwd).
43+
tmpdir.refresh();
44+
[
45+
['--permission'],
46+
['--permission', '-'],
47+
].forEach((args) => {
48+
const { status, stdout, stderr } = spawnSync(process.execPath, args, {
49+
cwd: tmpdir.path,
50+
input: 'console.log(process.permission.has("fs.read", ' +
51+
'require("path").join(process.cwd(), "x")))',
52+
});
53+
assert.strictEqual(status, 0, `${args} Error: ${stderr.toString()}`);
54+
assert.strictEqual(stdout.toString().trim(), 'false');
55+
});

0 commit comments

Comments
 (0)