Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ const databaseUrl = process.env.DATABASE_URL;
process.permission.drop('env', 'DATABASE_URL');
```

Wildcards cannot be dropped: `process.permission.drop('env', 'APP_*')` and
`process.permission.drop('env', '*')` throw `ERR_INVALID_ARG_VALUE`. To remove
every variable, drop the whole `env` scope.

When a process that enforces the Permission Model spawns a child process, the
child is started with `--allow-env=*`: the environment it inherits only contains
variables that the parent had access to. The child can still read its own
Expand Down
2 changes: 1 addition & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -3250,7 +3250,7 @@ The available scopes are the same as [`process.permission.has()`][]:
* `fs.write` - File System write operations
* `child` - Child process spawning operations
* `env` - Environment variables. Dropping a variable removes it from the
environment
environment. A reference ending with `*` is not accepted
* `openssl.store` - Loading keys through OpenSSL STORE loaders
* `worker` - Worker thread spawning operation
* `net` - Network operations
Expand Down
8 changes: 8 additions & 0 deletions src/permission/permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ static void Drop(const FunctionCallbackInfo<Value>& args) {
// are not guaranteed to be valid UTF-8.
BufferValue resource(env->isolate(), args[1]);
if (resource.length() > 0) {
// A wildcard would drop more than one variable at once. Dropping the
// whole scope, without a reference, is the only way to do that.
if (scope == PermissionScope::kEnv &&
resource.ToStringView().back() == '*') {
return THROW_ERR_INVALID_ARG_VALUE(
env,
"Wildcards are not supported when dropping environment variables");
}
env->permission()->Drop(env, scope, resource.ToStringView());
return;
}
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-permission-env-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ spawnSyncAndAssert(
],
{ env },
{});

// Wildcards cannot be dropped, and nothing is removed.
spawnSyncAndAssert(
process.execPath,
[
'--permission', '--allow-env=PERMISSION_ENV_*', '-e',
`
const assert = require('assert');
for (const reference of ['PERMISSION_ENV_*', '*']) {
assert.throws(() => process.permission.drop('env', reference), {
code: 'ERR_INVALID_ARG_VALUE',
});
}
assert.strictEqual(process.permission.has('env', 'PERMISSION_ENV_ONE'), true);
assert.strictEqual(process.env.PERMISSION_ENV_ONE, 'one');
assert.strictEqual(process.env.PERMISSION_ENV_TWO, 'two');
`,
],
{ env },
{});
Loading