Skip to content

Add --allow-env flag to Permission Model for restricting environment variable access #62424

Description

@himself65

What is the problem this feature will solve?

The Node.js Permission Model (stable as of v23.5.0) allows restricting access to the filesystem, network, child processes, and worker threads — but there is currently no way to restrict a process's access to environment variables.

This is a growing practical security concern. When running third-party code — such as MCP (Model Context Protocol) servers, CLI tools via npx, or untrusted npm packages — the process inherits the full environment of the parent shell, which often contains sensitive secrets:

OPENAI_API_KEY=sk-...
DATABASE_URL=postgres://...
AWS_SECRET_ACCESS_KEY=...
ANTHROPIC_API_KEY=sk-ant-...

Context: https://x.com/hnykda/status/2036414330267193815

Any package you run can silently exfiltrate these via process.env with no indication to the user.

What is the feature you are proposing to solve the problem?

Add an --allow-env flag to the Permission Model, mirroring Deno's implementation:

# Block all env var access
node --permission script.js

# Allow all env vars
node --permission --allow-env script.js

# Allow only specific env vars
node --permission --allow-env=PORT,NODE_ENV script.js

Attempts to read a disallowed variable via process.env would throw ERR_ACCESS_DENIED, consistent with other permission violations.

Runtime checking would be available via:

process.permission.has('env');
process.permission.has('env', 'PORT');

What alternatives have you considered?

The rise of agentic AI tooling (MCP servers, AI CLI agents, etc.) means developers are increasingly running third-party Node.js processes inside their development environments, where shells are pre-loaded with sensitive credentials. This is a meaningful and growing attack surface.

Deno has had this since v1.9. The prior discussion in nodejs/security-wg#993 raised concerns about complexity, but the threat model has materially changed since 2023.

Prior Art

Activity

  1. nabeel378 commented on Apr 8, 2026

    @nabeel378
    Contributor

    Revisiting this given how Node.js is used today (AI agents, npx, untrusted code). The risk now is more about accidental leakage of sensitive env vars.

    While this can be handled at the shell level, a minimal built-in approach (e.g. boolean --allow-env) could improve safety and consistency.

    I'd like to work on this feature. I’m currently researching the implementation and will share a proposal or PR soon.

  2. RafaelGSS commented on Apr 11, 2026

    @RafaelGSS
    Member

    I'm happy to review a draft of it.

  3. nabeel378 commented on Apr 11, 2026

    @nabeel378
    Contributor

    @RafaelGSS Thanks! I’ll start working on PR and share it soon.

  4. nabeel378 commented on Apr 21, 2026

    @nabeel378
    Contributor

    @RafaelGSS it’s done, please review: #62827

    cc:@himself65 @Renegade334 @jasnell

  5. github-actions commented on Jul 21, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions