| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent efbede6 commit e0f0830
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2316,6 +2316,9 @@ changes: | |||
| 2316 | 2316 | Enable the Permission Model for current process. When enabled, the | |
| 2317 | 2317 | following permissions are restricted: | |
| 2318 | 2318 | ||
| 2319 | + > See also [`--permission-audit`](#--permission-audit) for an audit-only mode | ||
| 2320 | + > that logs violations without denying access. | ||
| 2321 | + | ||
| 2319 | 2322 | * File System - manageable through | |
| 2320 | 2323 | [`--allow-fs-read`][], [`--allow-fs-write`][] flags | |
| 2321 | 2324 | * Network - manageable through [`--allow-net`][] flag | |
@@ -2331,9 +2334,22 @@ following permissions are restricted: | |||
| 2331 | 2334 | added: v25.8.0 | |
| 2332 | 2335 | --> | |
| 2333 | 2336 | ||
| 2334 | - Enable audit only for the permission model. When enabled, permission checks | ||
| 2335 | - are performed but access is not denied. Instead, a warning is emitted for | ||
| 2336 | - each permission violation via diagnostics channel. | ||
| 2337 | + Enable audit mode for the permission model. When enabled, permission checks | ||
| 2338 | + are performed but access is **not** denied — no `ERR_ACCESS_DENIED` error is | ||
| 2339 | + thrown. Instead, each permission violation is published through the | ||
| 2340 | + `node:diagnostics_channel` module, and execution continues normally. | ||
| 2341 | + | ||
| 2342 | + This flag does not require [`--permission`](#--permission) to be specified. The | ||
| 2343 | + `--allow-*` flags are not needed in audit mode, since no | ||
| 2344 | + access is denied. | ||
| 2345 | + | ||
| 2346 | + Audit mode is useful for discovering what permissions your application | ||
| 2347 | + requires before deploying with [`--permission`](#--permission). See the | ||
| 2348 | + [Permission Model][] documentation for the list of diagnostics channel names | ||
| 2349 | + and the message format. | ||
| 2350 | + | ||
| 2351 | + If both [`--permission`](#--permission) and `--permission-audit` are specified, | ||
| 2352 | + `--permission` takes precedence and the Permission Model runs in enforce mode. | ||
| 2337 | 2353 | ||
| 2338 | 2354 | ### `--preserve-symlinks` | |
| 2339 | 2355 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,17 @@ will restrict access to all available permissions. | |||
| 48 | 48 | The available permissions are documented by the [`--permission`][] | |
| 49 | 49 | flag. | |
| 50 | 50 | ||
| 51 | + The Permission Model has two operational modes: | ||
| 52 | + | ||
| 53 | + * **Enforce mode** (default when using [`--permission`][]): Access is denied and | ||
| 54 | + an `ERR_ACCESS_DENIED` error is thrown for any operation the process has not | ||
| 55 | + been granted permission to perform. | ||
| 56 | + * **Audit mode** (when using [`--permission-audit`][]): Permission checks are | ||
| 57 | + performed and violations are published through the diagnostics channel, but | ||
| 58 | + access is **not** denied. Execution continues normally. This mode is useful | ||
| 59 | + for discovering what permissions your application requires before deploying | ||
| 60 | + with enforce mode. | ||
| 61 | + | ||
| 51 | 62 | When starting Node.js with `--permission`, | |
| 52 | 63 | the ability to access the file system through the `fs` module, access the network, | |
| 53 | 64 | spawn processes, use `node:worker_threads`, use native addons, use WASI, use | |
@@ -77,8 +88,8 @@ flag. For WASI, use the [`--allow-wasi`][] flag. For FFI, use the | |||
| 77 | 88 | #### Runtime API | |
| 78 | 89 | ||
| 79 | 90 | When enabling the Permission Model through the [`--permission`][] | |
| 80 | - flag a new property `permission` is added to the `process` object. | ||
| 81 | - This property contains the following functions: | ||
| 91 | + or [`--permission-audit`][] flags, a new property `permission` is added to the | ||
| 92 | + `process` object. This property contains the following functions: | ||
| 82 | 93 | ||
| 83 | 94 | ##### `permission.has(scope[, reference])` | |
| 84 | 95 | ||
@@ -127,6 +138,56 @@ process.permission.has('fs.read', '/etc/myapp/config.json'); // false | |||
| 127 | 138 | process.permission.drop('child'); | |
| 128 | 139 | ``` | |
| 129 | 140 | ||
| 141 | + #### Audit Mode | ||
| 142 | + | ||
| 143 | + The [`--permission-audit`][] flag enables audit mode for the Permission Model. | ||
| 144 | + In audit mode, permission checks are performed but access is **not** denied — | ||
| 145 | + no `ERR_ACCESS_DENIED` error is thrown. Instead, each permission violation is | ||
| 146 | + published through the `node:diagnostics_channel` module, allowing the | ||
| 147 | + application to observe and log which operations would be denied under enforce | ||
| 148 | + mode. Execution continues normally. | ||
| 149 | + | ||
| 150 | + Audit mode is useful for discovering what permissions your application | ||
| 151 | + requires before deploying with [`--permission`][]. It can also be combined | ||
| 152 | + with the [`--allow-fs-read`][], [`--allow-fs-write`][], [`--allow-net`][], | ||
| 153 | + [`--allow-child-process`][], [`--allow-worker`][], [`--allow-addons`][], | ||
| 154 | + [`--allow-wasi`][], and [`--allow-ffi`][] flags to audit a subset of | ||
| 155 | + permissions while granting others. | ||
| 156 | + | ||
| 157 | + When a permission check fails in audit mode, a message is published to the | ||
| 158 | + diagnostics channel corresponding to the denied scope. The channel names are: | ||
| 159 | + | ||
| 160 | + * `node:permission-model:fs` — File System (read and write) | ||
| 161 | + * `node:permission-model:net` — Network | ||
| 162 | + * `node:permission-model:child` — Child Process | ||
| 163 | + * `node:permission-model:worker` — Worker Threads | ||
| 164 | + * `node:permission-model:inspector` — Inspector | ||
| 165 | + * `node:permission-model:wasi` — WASI | ||
| 166 | + * `node:permission-model:addon` — Native Addons | ||
| 167 | + * `node:permission-model:ffi` — FFI | ||
| 168 | + | ||
| 169 | + Each message is an object with the following properties: | ||
| 170 | + | ||
| 171 | + * `permission` {string} The name of the denied permission scope. | ||
| 172 | + * `resource` {string} The resource that access was denied to (e.g. a file path | ||
| 173 | + or host). | ||
| 174 | + | ||
| 175 | + ```js | ||
| 176 | + const diagnostics_channel = require('node:diagnostics_channel'); | ||
| 177 | + | ||
| 178 | + diagnostics_channel.channel('node:permission-model:fs').subscribe((msg) => { | ||
| 179 | + console.log(`Permission denied: ${msg.permission} on ${msg.resource}`); | ||
| 180 | + }); | ||
| 181 | + | ||
| 182 | + // Running with --permission-audit, this publishes a diagnostics channel | ||
| 183 | + // message but does not throw | ||
| 184 | + const fs = require('node:fs'); | ||
| 185 | + fs.readFileSync('/etc/passwd'); | ||
| 186 | + ``` | ||
| 187 | + | ||
| 188 | + If both [`--permission`][] and [`--permission-audit`][] are specified, | ||
| 189 | + `--permission` takes precedence and the Permission Model runs in enforce mode. | ||
| 190 | + | ||
| 130 | 191 | #### File System Permissions | |
| 131 | 192 | ||
| 132 | 193 | The Permission Model, by default, restricts access to the file system through the `node:fs` module. | |
@@ -324,6 +385,7 @@ Developers relying on --permission to sandbox untrusted code should be aware tha | |||
| 324 | 385 | [`--allow-net`]: cli.md#--allow-net | |
| 325 | 386 | [`--allow-wasi`]: cli.md#--allow-wasi | |
| 326 | 387 | [`--allow-worker`]: cli.md#--allow-worker | |
| 388 | + [`--permission-audit`]: cli.md#--permission-audit | ||
| 327 | 389 | [`--permission`]: cli.md#--permission | |
| 328 | 390 | [`npx`]: https://docs.npmjs.com/cli/commands/npx | |
| 329 | 391 | [`permission.has()`]: process.md#processpermissionhasscope-reference | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3127,7 +3127,8 @@ added: v20.0.0 | |||
| 3127 | 3127 | ||
| 3128 | 3128 | * Type: {Object} | |
| 3129 | 3129 | ||
| 3130 | - This API is available through the [`--permission`][] flag. | ||
| 3130 | + This API is available through the [`--permission`][] or | ||
| 3131 | + [`--permission-audit`][] flags. | ||
| 3131 | 3132 | ||
| 3132 | 3133 | `process.permission` is an object whose methods are used to manage permissions | |
| 3133 | 3134 | for the current process. Additional documentation is available in the | |
@@ -3148,6 +3149,9 @@ If no reference is provided, a global scope is assumed, for instance, | |||
| 3148 | 3149 | `process.permission.has('fs.read')` will check if the process has ALL | |
| 3149 | 3150 | file system read permissions. | |
| 3150 | 3151 | ||
| 3152 | + In audit mode ([`--permission-audit`][]), this method still returns the actual | ||
| 3153 | + permission status, but denied operations will not throw `ERR_ACCESS_DENIED`. | ||
| 3154 | + | ||
| 3151 | 3155 | The reference has a meaning based on the provided scope. For example, | |
| 3152 | 3156 | the reference when the scope is File System means files and folders. | |
| 3153 | 3157 | ||
@@ -3182,6 +3186,10 @@ Drops the specified permission from the current process. This operation is | |||
| 3182 | 3186 | **irreversible** — once a permission is dropped, it cannot be restored through | |
| 3183 | 3187 | any Node.js API. | |
| 3184 | 3188 | ||
| 3189 | + In audit mode ([`--permission-audit`][]), dropping a permission takes effect, | ||
| 3190 | + but since denied operations do not throw, the impact is limited to changing the | ||
| 3191 | + return value of `permission.has()`. | ||
| 3192 | + | ||
| 3185 | 3193 | If no reference is provided, the entire scope is dropped. For example, | |
| 3186 | 3194 | `process.permission.drop('fs.read')` will revoke ALL file system read | |
| 3187 | 3195 | permissions. | |
@@ -4612,6 +4620,7 @@ cases: | |||
| 4612 | 4620 | [`'message'`]: child_process.md#event-message | |
| 4613 | 4621 | [`'uncaughtException'`]: #event-uncaughtexception | |
| 4614 | 4622 | [`--no-deprecation`]: cli.md#--no-deprecation | |
| 4623 | + [`--permission-audit`]: cli.md#--permission-audit | ||
| 4615 | 4624 | [`--permission`]: cli.md#--permission | |
| 4616 | 4625 | [`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode | |
| 4617 | 4626 | [`Buffer`]: buffer.md | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1165,6 +1165,7 @@ developers may leverage to detect deprecated API usage. | |||
| 1165 | 1165 | .It Fl -permission | |
| 1166 | 1166 | Enable the Permission Model for current process. When enabled, the | |
| 1167 | 1167 | following permissions are restricted: | |
| 1168 | + | ||
| 1168 | 1169 | .Bl -bullet | |
| 1169 | 1170 | .It | |
| 1170 | 1171 | File System - manageable through | |
@@ -1184,9 +1185,19 @@ FFI - manageable through \fB--allow-ffi\fR flag | |||
| 1184 | 1185 | .El | |
| 1185 | 1186 | . | |
| 1186 | 1187 | .It Fl -permission-audit | |
| 1187 | - Enable audit only for the permission model. When enabled, permission checks | ||
| 1188 | - are performed but access is not denied. Instead, a warning is emitted for | ||
| 1189 | - each permission violation via diagnostics channel. | ||
| 1188 | + Enable audit mode for the permission model. When enabled, permission checks | ||
| 1189 | + are performed but access is \fBnot\fR denied — no \fBERR_ACCESS_DENIED\fR error is | ||
| 1190 | + thrown. Instead, each permission violation is published through the | ||
| 1191 | + \fBnode:diagnostics_channel\fR module, and execution continues normally. | ||
| 1192 | + This flag does not require \fB--permission\fR to be specified. The | ||
| 1193 | + \fB--allow-*\fR flags are not needed in audit mode, since no | ||
| 1194 | + access is denied. | ||
| 1195 | + Audit mode is useful for discovering what permissions your application | ||
| 1196 | + requires before deploying with \fB--permission\fR. See the | ||
| 1197 | + Permission Model documentation for the list of diagnostics channel names | ||
| 1198 | + and the message format. | ||
| 1199 | + If both \fB--permission\fR and \fB--permission-audit\fR are specified, | ||
| 1200 | + \fB--permission\fR takes precedence and the Permission Model runs in enforce mode. | ||
| 1190 | 1201 | . | |
| 1191 | 1202 | .It Fl -preserve-symlinks | |
| 1192 | 1203 | Instructs the module loader to preserve symbolic links when resolving and | |
| Back | FazBrowse Home | New Git URL |
0 commit comments