GeezerVison is showing github.com — src,permission: do not grant cwd read access without entrypoint · nodejs/node@0529e78
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/env.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1162,7 +1162,7 @@ Environment::Environment(IsolateData* isolate_data, | 1162 | 1162 | } | 1163 | 1163 | } | 1164 | 1164 |
| 1165 | | - if (first_argv != "inspect") { | | 1165 | + if (!first_argv.empty() && first_argv != "-" && first_argv != "inspect") { | 1166 | 1166 | options_->allow_fs_read.push_back(first_argv); | 1167 | 1167 | } | 1168 | 1168 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-permission-fs-read-entrypoint.js +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ if (!common.hasCrypto) { | 14 | 14 |
| 15 | 15 | const assert = require('assert'); | 16 | 16 | const fixtures = require('../common/fixtures'); | | 17 | +const tmpdir = require('../common/tmpdir'); | 17 | 18 | const { spawnSync } = require('child_process'); | 18 | 19 |
| 19 | 20 | const file = fixtures.path('permission', 'hello-world.js'); | @@ -36,3 +37,19 @@ const fsReadLoader = fixtures.path('permission', 'fs-read-loader.js'); | 36 | 37 | ); | 37 | 38 | assert.strictEqual(status, 0, `${arg0} Error: ${stderr.toString()}`); | 38 | 39 | }); | | 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 | +}); |
|