Skip to content

Commit 05b939b

Browse files
committed
permission: add path separator to loader check
1 parent 629047d commit 05b939b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function readPackageScope(checkPath) {
423423
checkPath = StringPrototypeSlice(checkPath, 0, separatorIndex);
424424
// Stop the search when the process doesn't have permissions
425425
// to walk upwards
426-
if (enabledPermission && !permission.has('fs.read', checkPath)) {
426+
if (enabledPermission && !permission.has('fs.read', checkPath + sep)) {
427427
return false;
428428
}
429429
if (StringPrototypeEndsWith(checkPath, sep + 'node_modules'))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const fs = require('node:fs');
2+
3+
fs.readFile('/etc/passwd', () => {});

test/parallel/test-cli-permission-deny-fs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
'use strict';
22

33
require('../common');
4+
5+
const fixtures = require('../common/fixtures');
46
const { spawnSync } = require('child_process');
57
const assert = require('assert');
68
const fs = require('fs');
9+
const path = require('path');
710

811
{
912
const { status, stdout } = spawnSync(
@@ -126,3 +129,21 @@ const fs = require('fs');
126129
assert.strictEqual(status, 1);
127130
assert.ok(!fs.existsSync('permission-deny-example.md'));
128131
}
132+
133+
{
134+
const firstPath = path.sep + process.cwd().split(path.sep)[1];
135+
const pwd = fixtures.path('permission', 'loader');
136+
const file = path.join(pwd, 'index.js');
137+
const { status, stderr } = spawnSync(
138+
process.execPath,
139+
[
140+
'--experimental-permission',
141+
`--allow-fs-read=${firstPath}`,
142+
file,
143+
]
144+
);
145+
assert.ok(
146+
stderr.toString().includes('resource: \'/etc/passwd\''),
147+
stderr);
148+
assert.strictEqual(status, 1);
149+
}

0 commit comments

Comments
 (0)