Skip to content

Conversation

@dsherret
Copy link
Member

@dsherret dsherret commented Nov 4, 2025

Adds the ability to ignore certain environment variables and return undefined instead of erroring.

> cat main.ts
console.log(Deno.env.get("VAR1"));
console.log(Deno.env.get("VAR2"));
console.log(Deno.env.toObject());
> VAR1=1 VAR2=2 deno run --ignore-env main.ts
undefined
undefined
[Object: null prototype] {}
> VAR1=1 VAR2=2 deno run --ignore-env=VAR1 --allow-env=VAR2 main.ts
undefined
2
[Object: null prototype] { VAR2: "2" }

Also doesn't error anymore when doing --allow-env --deny-env=SOMETHING and getting all env vars.

Closes #30891
Closes #31071

@bartlomieju
Copy link
Member

Closes #31071?

@dsherret dsherret marked this pull request as ready for review November 5, 2025 16:14
@bartlomieju
Copy link
Member

Can you please update the docs for permissions and show an example what happens if you use --ignore-env --deny-env=VAR1?

Comment on lines +179 to +182
fn check_env_with_maybe_exit(
state: &mut OpState,
key: &str,
) -> Result<ControlFlow<()>, PermissionCheckError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a nice solution 👍

Comment on lines 16 to 20
"some_allow_env": {
"args": "run --ignore-env=VAR1 --allow-env main.ts",
"output": "undefined\n2\n[WILDCARD]"
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add --ignore-env and --deny-env interaction here? And preferably all three too

@bartlomieju
Copy link
Member

Not a blocker, but we should update the interactive prompt with the i option as well - but it should be selective only to the env permission

Copilot AI review requested due to automatic review settings November 6, 2025 16:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for ignoring specific environment variables through the new --ignore-env flag and ignore configuration option. When an environment variable is ignored, attempts to access it return undefined (or are excluded from Deno.env.toObject()) without raising a permission error, providing a way to hide sensitive environment variables from scripts without requiring explicit permission denials.

Key Changes:

  • Introduces new PermissionState::Ignored and PermissionState::DeniedPartial states to the permission system
  • Adds --ignore-env CLI flag and corresponding configuration support for environment permissions
  • Refactors NODE_ENV_VAR_ALLOWLIST from a lazy-initialized HashSet to a sorted const array for more efficient lookups

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/specs/run/permission_env_allow_and_deny/main.ts Updates test to verify env vars are properly filtered with allow/deny flags
tests/specs/run/permission_env_allow_and_deny/main.out Removes expected error output as test now succeeds with proper permission setup
tests/specs/run/permission_env_allow_and_deny/__test__.jsonc Updates test config to use allow/deny flags without expecting errors
tests/specs/permission/ignore_env/flags/main.ts New test for --ignore-env flag functionality
tests/specs/permission/ignore_env/flags/__test__.jsonc Test configurations for various --ignore-env scenarios (all, some, with allow-env, with deny-env)
tests/specs/permission/ignore_env/config/main.ts New test for ignore configuration via deno.json
tests/specs/permission/ignore_env/config/deno.json Config file demonstrating ignore: true setting for env permissions
tests/specs/permission/ignore_env/config/__test__.jsonc Test configuration for ignore via config file
runtime/permissions/lib.rs Core implementation: adds Ignored/DeniedPartial states, implements ignore list tracking, updates permission query logic
runtime/ops/permissions.rs Updates PermissionStatus conversion to handle new permission states
libs/config/deno_json/permissions.rs Adds AllowDenyIgnorePermissionConfig struct and deserialization support
libs/config/deno_json/mod.rs Exports new AllowDenyIgnore config types
ext/os/lib.rs Implements ignore behavior in env operations (get/set/delete/toObject), refactors NODE_ENV_VAR_ALLOWLIST to const array
cli/schemas/config-file.v1.json Defines JSON schema for ignore permission config
cli/args/mod.rs Integrates ignore_env into permissions options, renames no_op to identity for clarity
cli/args/flags.rs Adds ignore_env flag parsing, serialization, and test coverage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dsherret dsherret marked this pull request as draft November 7, 2025 20:44
@dsherret
Copy link
Member Author

dsherret commented Nov 7, 2025

Converting to draft. Going to do a bigger overhaul to the permission system in a separate PR before merging.

"deny": { "$ref": "#/$defs/permissionConfigValue" },
"ignore": { "$ref": "#/$defs/permissionConfigValue" }
}
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be used in "env" before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spefic permission for enumerating environment keys. Permission configuration: Acknowledging a permission being read, but 'ignore' it.

2 participants