Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1f2fcf1
doc: add history entries for JSON modules stabilization
aduh95 Nov 16, 2024
00e092b
util: fix util.getCallSites plurality
legendecas Nov 2, 2024
d4e7926
util: add sourcemap support to getCallSites
marco-ippolito Nov 4, 2024
7814669
tools: fix c-ares updater script for Node.js 18
richardlau Nov 6, 2024
bbb8f59
lib: use `Promise.withResolvers()` in timers
anonrig Nov 6, 2024
e147935
deps: update icu to 76.1
nodejs-github-bot Nov 7, 2024
cfe28b1
lib: remove unnecessary optional chaining
gurgunday Nov 7, 2024
d1ad43e
test: improve test coverage for `ServerResponse`
juanarbol Nov 7, 2024
5767b76
doc: enforce strict policy to semver-major releases
RafaelGSS Nov 7, 2024
e1b42e7
test: add buffer to fs_permission tests
RafaelGSS Nov 7, 2024
1568733
lib: prefer symbol to number in webidl `type` function
aduh95 Nov 7, 2024
9862912
assert: differentiate cases where `cause` is `undefined` or missing
aduh95 Nov 8, 2024
e1f54e2
test: ensure that test priority is not higher than current priority
LiviaMedeiros Nov 8, 2024
8576ca9
doc: clarify removal of experimental API does not require a deprecation
aduh95 Nov 8, 2024
db0d648
fs: fix bufferSize option for opendir recursive
Ethan-Arrowood Nov 8, 2024
3a9733c
util: do not mark experimental feature as deprecated
aduh95 Nov 8, 2024
84c4747
test: improve test coverage for child process message sending
juanarbol Nov 8, 2024
ccb69bb
src: add cli option to preserve env vars on dr
RafaelGSS Nov 8, 2024
16786a6
src: improve `node:os` userInfo performance
anonrig Nov 8, 2024
aa12de0
doc: sort --report-exclude alphabetically
RafaelGSS Nov 9, 2024
419ea06
tools: remove non-existent file from eslint config
avivkeller Nov 10, 2024
8111a76
tools: make commit-queue check blocked label
marco-ippolito Nov 10, 2024
3cfacd3
tools: fix exclude labels for commit-queue
richardlau Nov 10, 2024
bba7323
build: apply cpp linting and formatting to ncrypto
avivkeller Nov 10, 2024
7773567
build: use glob for dependencies of out/Makefile
richardlau Nov 10, 2024
df5ea1a
doc: clarify triager role
gireeshpunathil Nov 10, 2024
472d55e
build: implement node_use_amaro flag in GN build
zcbenz Nov 11, 2024
9aeb671
doc: run license-builder
github-actions[bot] Nov 11, 2024
83ba688
esm: fix import.meta.resolve crash
marco-ippolito Nov 11, 2024
9c99255
permission: ignore internalModuleStat on module loading
RafaelGSS Nov 11, 2024
c210335
benchmark: add `test_runner/mock-fn`
avivkeller Nov 11, 2024
e0db9ed
deps: update c-ares to v1.34.3
nodejs-github-bot Nov 12, 2024
5a437c4
report: fix network queries in getReport libuv with exclude-network
Tofandel Nov 12, 2024
770670c
test: fix permission fixtures lint
RafaelGSS Nov 12, 2024
65ffb2c
doc: update unflag info of `import.meta.resolve`
skyclouds2001 Nov 12, 2024
c5afdaf
doc: correct max-semi-space-size statement
joebowbeer Nov 12, 2024
11e1bdd
module: tidy code string concat → string templates
JakobJingleheimer Nov 13, 2024
e56265c
doc: fix history info for `URL.prototype.toJSON`
aduh95 Nov 13, 2024
787e51e
doc: add notable-change mention to sec release
RafaelGSS Nov 14, 2024
bdb6d12
events: add hasEventListener util for validate
sungpaks Nov 14, 2024
a831184
doc: clarify UV_THREADPOOL_SIZE env var usage
preveen-stack Nov 15, 2024
1b863b9
doc: add `-S` flag release preparation example
aduh95 Nov 15, 2024
32e5bbc
benchmark: add `test-reporters`
avivkeller Nov 16, 2024
ec953bc
doc: add `node:sqlite` to mandatory `node:` prefix list
sapphi-red Nov 16, 2024
e0ef65b
doc: remove non-working example
aduh95 Nov 16, 2024
dc8aca3
deps: update undici to 6.21.0
nodejs-github-bot Nov 16, 2024
cad557e
deps: update simdutf to 5.6.1
nodejs-github-bot Nov 16, 2024
58d7a6e
Revert "src: migrate `String::Value` to `String::ValueView`"
targos Nov 16, 2024
49d5522
src: use env strings to create sqlite results
targos Nov 17, 2024
034505e
test_runner: error on mocking an already mocked date
avivkeller Nov 17, 2024
d41cb49
fs: prevent unwanted `dependencyOwners` removal
Ceres6 Nov 17, 2024
e0c2225
crypto: allow length=0 for HKDF and PBKDF2 in SubtleCrypto.deriveBits
panva Nov 17, 2024
44324aa
tools: bump @eslint/plugin-kit from 0.2.0 to 0.2.3 in /tools/eslint
dependabot[bot] Nov 17, 2024
bcbba72
sqlite: add support for SQLite Session Extension
louwers Nov 18, 2024
693fda0
lib: remove unused file `fetch_module`
targos Nov 18, 2024
72f82ad
2024-11-20, Version 23.3.0 (Current)
RafaelGSS Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
permission: ignore internalModuleStat on module loading
This improves Permission Model usage when allowing read access to
specifi modules. To achieve that, the permission model check on
internalModuleStat has been removed meaning that on module loading,
uv_fs_stat is performed on files and folders even when the permission
model is enabled. Although a uv_fs_stat is performed, reading/executing
the module will still pass by the permission model check.

Without this PR when an app tries to --allow-fs-read=./a.js
--allow-fs-read=./b.js where `a` attempt to load b, it will fails as
it reads $pwd and no permission has been given to this path.

PR-URL: #55797
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
  • Loading branch information
RafaelGSS authored and aduh95 committed Nov 16, 2024
commit 9c99255468d8d2ad9acc2fa65e54baad53ad7531
27 changes: 0 additions & 27 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,8 @@ The initializer module also needs to be allowed. Consider the following example:

```console
$ node --experimental-permission t.js
node:internal/modules/cjs/loader:162
const result = internalModuleStat(receiver, filename);
^

Error: Access to this API has been restricted
at stat (node:internal/modules/cjs/loader:162:18)
at Module._findPath (node:internal/modules/cjs/loader:640:16)
at resolveMainPath (node:internal/modules/run_main:15:25)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:53:24)
at node:internal/main/run_main_module:23:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
Expand Down Expand Up @@ -300,18 +293,8 @@ new WASI({

```console
$ node --experimental-permission --allow-fs-read=* index.js
node:wasi:99
const wrap = new _WASI(args, env, preopens, stdio);
^

Error: Access to this API has been restricted
at new WASI (node:wasi:99:18)
at Object.<anonymous> (/home/index.js:3:1)
at Module._compile (node:internal/modules/cjs/loader:1476:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1555:10)
at Module.load (node:internal/modules/cjs/loader:1288:32)
at Module._load (node:internal/modules/cjs/loader:1104:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:191:14)
at node:internal/main/run_main_module:30:49 {
code: 'ERR_ACCESS_DENIED',
permission: 'WASI',
Expand Down Expand Up @@ -341,18 +324,8 @@ new Worker(__filename);

```console
$ node --experimental-permission --allow-fs-read=* index.js
node:internal/worker:188
this[kHandle] = new WorkerImpl(url,
^

Error: Access to this API has been restricted
at new Worker (node:internal/worker:188:21)
at Object.<anonymous> (/home/index.js.js:3:1)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'WorkerThreads'
Expand Down
7 changes: 0 additions & 7 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@ will be restricted.

```console
$ node --experimental-permission index.js
node:internal/modules/cjs/loader:171
const result = internalModuleStat(receiver, filename);
^

Error: Access to this API has been restricted
at stat (node:internal/modules/cjs/loader:171:18)
at Module._findPath (node:internal/modules/cjs/loader:627:16)
at resolveMainPath (node:internal/modules/run_main:19:25)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:24)
at node:internal/main/run_main_module:23:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
Expand Down
6 changes: 1 addition & 5 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const packageJsonReader = require('internal/modules/package_json_reader');
const { getOptionValue, getEmbedderOptions } = require('internal/options');
const shouldReportRequiredModules = getLazy(() => process.env.WATCH_REPORT_DEPENDENCIES);

const permission = require('internal/process/permission');
const {
vm_dynamic_import_default_internal,
} = internalBinding('symbols');
Expand Down Expand Up @@ -729,11 +728,8 @@ Module._findPath = function(request, paths, isMain) {
// For each path
for (let i = 0; i < paths.length; i++) {
// Don't search further if path doesn't exist
// or doesn't have permission to it
const curPath = paths[i];
if (insidePath && curPath &&
((permission.isEnabled() && !permission.has('fs.read', curPath)) || _stat(curPath) < 1)
) {
if (insidePath && curPath && _stat(curPath) < 1) {
continue;
}

Expand Down
6 changes: 2 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
// Used to speed up module loading. Returns 0 if the path refers to
// a file, 1 when it's a directory or < 0 on error (usually -ENOENT.)
// The speedup comes from not creating thousands of Stat and Error objects.
// Do not expose this function through public API as it doesn't hold
// Permission Model checks.
static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Expand All @@ -1045,8 +1047,6 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
BufferValue path(env->isolate(), args[1]);
CHECK_NOT_NULL(*path);
ToNamespacedPath(env, &path);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());

uv_fs_t req;
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
Expand All @@ -1069,8 +1069,6 @@ static int32_t FastInternalModuleStat(
HandleScope scope(env->isolate());

auto path = std::filesystem::path(input.data, input.data + input.length);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, path.string(), -1);

switch (std::filesystem::status(path).type()) {
case std::filesystem::file_type::directory:
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/permission/fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ const regularFile = __filename;
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFolder),
}));
assert.throws(() => {
fs.readdirSync(blockedFolder, { recursive: true });
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFolder),
}));
assert.throws(() => {
fs.readdirSync(blockedFolder);
}, common.expectsError({
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/permission/main-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./required-module');
1 change: 1 addition & 0 deletions test/fixtures/permission/main-module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './required-module.mjs';
1 change: 1 addition & 0 deletions test/fixtures/permission/required-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('ok');
1 change: 1 addition & 0 deletions test/fixtures/permission/required-module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('ok');
12 changes: 3 additions & 9 deletions test/parallel/test-permission-fs-internal-module-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ if (!common.hasCrypto) {
}

const { internalBinding } = require('internal/test/binding');
const assert = require('node:assert');
const path = require('node:path');
const fixtures = require('../common/fixtures');

const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md');
const internalFsBinding = internalBinding('fs');

// Run this inside a for loop to trigger the fast API
for (let i = 0; i < 10_000; i++) {
assert.throws(() => {
internalFsBinding.internalModuleStat(internalFsBinding, blockedFile);
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFile),
});
// internalModuleStat does not use permission model.
// doesNotThrow
internalFsBinding.internalModuleStat(internalFsBinding, blockedFile);
}
76 changes: 76 additions & 0 deletions test/parallel/test-permission-fs-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Flags: --experimental-permission --allow-fs-read=* --allow-child-process
'use strict';

const common = require('../common');
common.skipIfWorker();
const fixtures = require('../common/fixtures');

const assert = require('node:assert');
const { spawnSync } = require('node:child_process');

{
const mainModule = fixtures.path('permission', 'main-module.js');
const requiredModule = fixtures.path('permission', 'required-module.js');
const { status, stdout, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read', mainModule,
'--allow-fs-read', requiredModule,
mainModule,
]
);

assert.strictEqual(status, 0, stderr.toString());
assert.strictEqual(stdout.toString(), 'ok\n');
}

{
// When required module is not passed as allowed path
const mainModule = fixtures.path('permission', 'main-module.js');
const { status, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read', mainModule,
mainModule,
]
);

assert.strictEqual(status, 1, stderr.toString());
assert.match(stderr.toString(), /Error: Access to this API has been restricted/);
}

{
// ESM loader test
const mainModule = fixtures.path('permission', 'main-module.mjs');
const requiredModule = fixtures.path('permission', 'required-module.mjs');
const { status, stdout, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read', mainModule,
'--allow-fs-read', requiredModule,
mainModule,
]
);

assert.strictEqual(status, 0, stderr.toString());
assert.strictEqual(stdout.toString(), 'ok\n');
}

{
// When required module is not passed as allowed path (ESM)
const mainModule = fixtures.path('permission', 'main-module.mjs');
const { status, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read', mainModule,
mainModule,
]
);

assert.strictEqual(status, 1, stderr.toString());
assert.match(stderr.toString(), /Error: Access to this API has been restricted/);
}