@@ -3214,6 +3214,65 @@ process.permission.has('fs.read', './README.md');
32143214process .permission .has (' fs.read' );
32153215` ` `
32163216
3217+ ### ` process .permission .drop (scope[, reference])`
3218+
3219+ <!-- YAML
3220+ added: REPLACEME
3221+ -->
3222+
3223+ > Stability: 1.1 - Active Development
3224+
3225+ * ` scope` {string}
3226+ * ` reference` {string}
3227+
3228+ Drops the specified permission from the current process. This operation is
3229+ **irreversible** — once a permission is dropped, it cannot be restored through
3230+ any Node.js API.
3231+
3232+ If no reference is provided, the entire scope is dropped. For example,
3233+ ` process .permission .drop (' fs.read' )` will revoke ALL file system read
3234+ permissions.
3235+
3236+ When a reference is provided, only the permission for that specific resource
3237+ is dropped. For example, ` process .permission .drop (' fs.read' , ' /etc/myapp' )`
3238+ will revoke read access to that directory while keeping other read
3239+ permissions intact.
3240+
3241+ **Important:** You can only drop the exact resource that was explicitly
3242+ granted. The reference passed to ` drop ()` must match the original grant:
3243+
3244+ * If a permission was granted using a wildcard (` * ` ), such as
3245+ ` -- allow- fs- read= * ` , individual paths cannot be dropped - only the entire
3246+ scope can be dropped (by calling ` drop ()` without a reference).
3247+ * If a directory was granted (e.g. ` -- allow- fs- read= / my/ folder` ), you cannot
3248+ drop access to individual files inside it. You must drop the same directory
3249+ that was granted. Any remaining grants continue to apply.
3250+
3251+ The available scopes are the same as [` process .permission .has ()` ][]:
3252+
3253+ * ` fs` - All File System (drops both read and write)
3254+ * ` fs .read ` - File System read operations
3255+ * ` fs .write ` - File System write operations
3256+ * ` child` - Child process spawning operations
3257+ * ` worker` - Worker thread spawning operation
3258+ * ` net` - Network operations
3259+ * ` inspector` - Inspector operations
3260+ * ` wasi` - WASI operations
3261+ * ` addon` - Native addon operations
3262+
3263+ ` ` ` js
3264+ const fs = require (' node:fs' );
3265+
3266+ // Read configuration during startup
3267+ const config = fs .readFileSync (' /etc/myapp/config.json' , ' utf8' );
3268+
3269+ // Drop read access to the config directory after initialization
3270+ process .permission .drop (' fs.read' , ' /etc/myapp' );
3271+
3272+ // This will now throw ERR_ACCESS_DENIED
3273+ fs .readFileSync (' /etc/myapp/config.json' );
3274+ ` ` `
3275+
32173276## ` process .pid `
32183277
32193278<!-- YAML
@@ -4642,6 +4701,7 @@ cases:
46424701[` process .hrtime ()` ]: #processhrtimetime
46434702[` process .hrtime .bigint ()` ]: #processhrtimebigint
46444703[` process .kill ()` ]: #processkillpid-signal
4704+ [` process .permission .has ()` ]: #processpermissionhasscope-reference
46454705[` process .setUncaughtExceptionCaptureCallback ()` ]: #processsetuncaughtexceptioncapturecallbackfn
46464706[` promise .catch ()` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
46474707[` queueMicrotask ()` ]: globals.md#queuemicrotaskcallback
0 commit comments