Skip to content

Commit f45c8e1

Browse files
tniessenUlisesGascon
authored andcommitted
doc,test: add known path resolution issue in permission model
As a side effect of 205f1e6, Node.js now resolves some paths differently when the permission model is enabled. While these are mostly edge cases, they are worth mentioning in the documentation. This commit also adds a known_issues test that demonstrates one such difference. PR-URL: #49155 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 40e9fcd commit f45c8e1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

doc/api/permissions.md

+2
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ Wildcards are supported too:
560560

561561
There are constraints you need to know before using this system:
562562

563+
* When the permission model is enabled, Node.js may resolve some paths
564+
differently than when it is disabled.
563565
* Native modules are restricted by default when using the Permission Model.
564566
* OpenSSL engines currently cannot be requested at runtime when the Permission
565567
Model is enabled, affecting the built-in crypto, https, and tls modules.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
// The permission model resolves paths to avoid path traversals, but in doing so
4+
// it potentially interprets paths differently than the operating system would.
5+
// This test demonstrates that merely enabling the permission model causes the
6+
// application to potentially access a different file than it would without the
7+
// permission model.
8+
9+
const common = require('../common');
10+
11+
const assert = require('assert');
12+
const { execFileSync } = require('child_process');
13+
const { mkdirSync, symlinkSync, writeFileSync } = require('fs');
14+
const path = require('path');
15+
16+
if (common.isWindows)
17+
assert.fail('not applicable to Windows');
18+
19+
const tmpdir = require('../common/tmpdir');
20+
tmpdir.refresh();
21+
22+
const a = path.join(tmpdir.path, 'a');
23+
const b = path.join(tmpdir.path, 'b');
24+
const c = path.join(tmpdir.path, 'c');
25+
const d = path.join(tmpdir.path, 'c/d');
26+
27+
writeFileSync(a, 'bad');
28+
symlinkSync('c/d', b);
29+
mkdirSync(c);
30+
mkdirSync(d);
31+
writeFileSync(path.join(c, 'a'), 'good');
32+
33+
function run(...args) {
34+
const interestingPath = `${tmpdir.path}/b/../a`;
35+
args = [...args, '-p', `fs.readFileSync(${JSON.stringify(interestingPath)}, 'utf8')`];
36+
return execFileSync(process.execPath, args, { encoding: 'utf8' }).trim();
37+
}
38+
39+
// Because this is a known_issues test, we cannot assert any assumptions besides
40+
// the known issue itself. Instead, do a sanity check and report success if the
41+
// sanity check fails.
42+
if (run() !== 'good') {
43+
process.exit(0);
44+
}
45+
46+
assert.strictEqual(run('--experimental-permission', `--allow-fs-read=${tmpdir.path}`), 'good');

0 commit comments

Comments
 (0)