GeezerVison is showing github.com — permission: ignore internalModuleStat on module loading · nodejs/node@2beb4f1
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: doc/api/cli.md -27Lines changed: 0 additions & 27 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -219,15 +219,8 @@ The initializer module also needs to be allowed. Consider the following example: | 219 | 219 |
| 220 | 220 | ```console | 221 | 221 | $ node --experimental-permission t.js | 222 | | -node:internal/modules/cjs/loader:162 | 223 | | - const result = internalModuleStat(receiver, filename); | 224 | | - ^ | 225 | 222 |
| 226 | 223 | Error: Access to this API has been restricted | 227 | | - at stat (node:internal/modules/cjs/loader:162:18) | 228 | | - at Module._findPath (node:internal/modules/cjs/loader:640:16) | 229 | | - at resolveMainPath (node:internal/modules/run_main:15:25) | 230 | | - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:53:24) | 231 | 224 | at node:internal/main/run_main_module:23:47 { | 232 | 225 | code: 'ERR_ACCESS_DENIED', | 233 | 226 | permission: 'FileSystemRead', | @@ -298,18 +291,8 @@ new WASI({ | 298 | 291 |
| 299 | 292 | ```console | 300 | 293 | $ node --experimental-permission --allow-fs-read=* index.js | 301 | | -node:wasi:99 | 302 | | - const wrap = new _WASI(args, env, preopens, stdio); | 303 | | - ^ | 304 | 294 |
| 305 | 295 | Error: Access to this API has been restricted | 306 | | - at new WASI (node:wasi:99:18) | 307 | | - at Object.<anonymous> (/home/index.js:3:1) | 308 | | - at Module._compile (node:internal/modules/cjs/loader:1476:14) | 309 | | - at Module._extensions..js (node:internal/modules/cjs/loader:1555:10) | 310 | | - at Module.load (node:internal/modules/cjs/loader:1288:32) | 311 | | - at Module._load (node:internal/modules/cjs/loader:1104:12) | 312 | | - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:191:14) | 313 | 296 | at node:internal/main/run_main_module:30:49 { | 314 | 297 | code: 'ERR_ACCESS_DENIED', | 315 | 298 | permission: 'WASI', | @@ -339,18 +322,8 @@ new Worker(__filename); | 339 | 322 |
| 340 | 323 | ```console | 341 | 324 | $ node --experimental-permission --allow-fs-read=* index.js | 342 | | -node:internal/worker:188 | 343 | | - this[kHandle] = new WorkerImpl(url, | 344 | | - ^ | 345 | 325 |
| 346 | 326 | Error: Access to this API has been restricted | 347 | | - at new Worker (node:internal/worker:188:21) | 348 | | - at Object.<anonymous> (/home/index.js.js:3:1) | 349 | | - at Module._compile (node:internal/modules/cjs/loader:1120:14) | 350 | | - at Module._extensions..js (node:internal/modules/cjs/loader:1174:10) | 351 | | - at Module.load (node:internal/modules/cjs/loader:998:32) | 352 | | - at Module._load (node:internal/modules/cjs/loader:839:12) | 353 | | - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) | 354 | 327 | at node:internal/main/run_main_module:17:47 { | 355 | 328 | code: 'ERR_ACCESS_DENIED', | 356 | 329 | permission: 'WorkerThreads' | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/permissions.md -7Lines changed: 0 additions & 7 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,15 +47,8 @@ will be restricted. | 47 | 47 |
| 48 | 48 | ```console | 49 | 49 | $ node --experimental-permission index.js | 50 | | -node:internal/modules/cjs/loader:171 | 51 | | - const result = internalModuleStat(receiver, filename); | 52 | | - ^ | 53 | 50 |
| 54 | 51 | Error: Access to this API has been restricted | 55 | | - at stat (node:internal/modules/cjs/loader:171:18) | 56 | | - at Module._findPath (node:internal/modules/cjs/loader:627:16) | 57 | | - at resolveMainPath (node:internal/modules/run_main:19:25) | 58 | | - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:24) | 59 | 52 | at node:internal/main/run_main_module:23:47 { | 60 | 53 | code: 'ERR_ACCESS_DENIED', | 61 | 54 | permission: 'FileSystemRead', | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -159,7 +159,6 @@ const packageJsonReader = require('internal/modules/package_json_reader'); | 159 | 159 | const { getOptionValue, getEmbedderOptions } = require('internal/options'); | 160 | 160 | const shouldReportRequiredModules = getLazy(() => process.env.WATCH_REPORT_DEPENDENCIES); | 161 | 161 |
| 162 | | -const permission = require('internal/process/permission'); | 163 | 162 | const { | 164 | 163 | vm_dynamic_import_default_internal, | 165 | 164 | } = internalBinding('symbols'); | @@ -736,11 +735,8 @@ Module._findPath = function(request, paths, isMain) { | 736 | 735 | // For each path | 737 | 736 | for (let i = 0; i < paths.length; i++) { | 738 | 737 | // Don't search further if path doesn't exist | 739 | | - // or doesn't have permission to it | 740 | 738 | const curPath = paths[i]; | 741 | | - if (insidePath && curPath && | 742 | | - ((permission.isEnabled() && !permission.has('fs.read', curPath)) || _stat(curPath) < 1) | 743 | | - ) { | | 739 | + if (insidePath && curPath && _stat(curPath) < 1) { | 744 | 740 | continue; | 745 | 741 | } | 746 | 742 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_file.cc +2-9Lines changed: 2 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1031,6 +1031,8 @@ static void ExistsSync(const FunctionCallbackInfo<Value>& args) { | 1031 | 1031 | // Used to speed up module loading. Returns 0 if the path refers to | 1032 | 1032 | // a file, 1 when it's a directory or < 0 on error (usually -ENOENT.) | 1033 | 1033 | // The speedup comes from not creating thousands of Stat and Error objects. | | 1034 | +// Do not expose this function through public API as it doesn't hold | | 1035 | +// Permission Model checks. | 1034 | 1036 | static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) { | 1035 | 1037 | Environment* env = Environment::GetCurrent(args); | 1036 | 1038 |
| @@ -1039,8 +1041,6 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) { | 1039 | 1041 | BufferValue path(env->isolate(), args[1]); | 1040 | 1042 | CHECK_NOT_NULL(*path); | 1041 | 1043 | ToNamespacedPath(env, &path); | 1042 | | - THROW_IF_INSUFFICIENT_PERMISSIONS( | 1043 | | - env, permission::PermissionScope::kFileSystemRead, path.ToStringView()); | 1044 | 1044 |
| 1045 | 1045 | uv_fs_t req; | 1046 | 1046 | int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr); | @@ -1067,15 +1067,8 @@ static int32_t FastInternalModuleStat( | 1067 | 1067 | } | 1068 | 1068 |
| 1069 | 1069 | HandleScope scope(isolate); | 1070 | | - Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked()); | 1071 | 1070 |
| 1072 | 1071 | auto path = std::filesystem::path(input.data, input.data + input.length); | 1073 | | - if (!env->permission()->is_granted( | 1074 | | - env, permission::PermissionScope::kFileSystemRead, path.string())) | 1075 | | - [[unlikely]] { | 1076 | | - options.fallback = true; | 1077 | | - return -1; | 1078 | | - } | 1079 | 1072 |
| 1080 | 1073 | switch (std::filesystem::status(path).type()) { | 1081 | 1074 | case std::filesystem::file_type::directory: | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/permission/fs-read.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -282,6 +282,13 @@ const regularFile = __filename; | 282 | 282 | permission: 'FileSystemRead', | 283 | 283 | resource: path.toNamespacedPath(blockedFolder), | 284 | 284 | })); | | 285 | + assert.throws(() => { | | 286 | + fs.readdirSync(blockedFolder, { recursive: true }); | | 287 | + }, common.expectsError({ | | 288 | + code: 'ERR_ACCESS_DENIED', | | 289 | + permission: 'FileSystemRead', | | 290 | + resource: path.toNamespacedPath(blockedFolder), | | 291 | + })); | 285 | 292 | assert.throws(() => { | 286 | 293 | fs.readdirSync(blockedFolder); | 287 | 294 | }, common.expectsError({ | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +require('./required-module'); |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import './required-module.mjs'; |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +console.log('ok'); |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +console.log('ok'); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-permission-fs-internal-module-stat.js +3-9Lines changed: 3 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,20 +9,14 @@ if (!common.hasCrypto) { | 9 | 9 | } | 10 | 10 |
| 11 | 11 | const { internalBinding } = require('internal/test/binding'); | 12 | | -const assert = require('node:assert'); | 13 | | -const path = require('node:path'); | 14 | 12 | const fixtures = require('../common/fixtures'); | 15 | 13 |
| 16 | 14 | const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md'); | 17 | 15 | const internalFsBinding = internalBinding('fs'); | 18 | 16 |
| 19 | 17 | // Run this inside a for loop to trigger the fast API | 20 | 18 | for (let i = 0; i < 10_000; i++) { | 21 | | - assert.throws(() => { | 22 | | - internalFsBinding.internalModuleStat(internalFsBinding, blockedFile); | 23 | | - }, { | 24 | | - code: 'ERR_ACCESS_DENIED', | 25 | | - permission: 'FileSystemRead', | 26 | | - resource: path.toNamespacedPath(blockedFile), | 27 | | - }); | | 19 | + // internalModuleStat does not use permission model. | | 20 | + // doesNotThrow | | 21 | + internalFsBinding.internalModuleStat(internalFsBinding, blockedFile); | 28 | 22 | } |
|