Skip to content

Permission - Environment variables #993

Closed as not planned
Closed as not planned
@daeyeon

Description

@daeyeon

Hello folks,

I recently made a PR related to environment variables permissions. I basically like the idea of explicitly knowing what resources an application is accessing when it runs.

There were some discussions about whether this permission itself is even necessary. And I started to have my own doubts. Since the environment variables is on the Security WG's permission model roadmap, I'd like to move the discussion here to continue with everyone's thoughts.


1. Needed?

This is for providing transparency about which environment variables are being accessed. It informs users by throwing an error when attempts to access disallowed variables occur. Additionally, it allows for setting up an allowlist in a consistent manner, regardless of platforms.

2. How to do?

The current proposal is to add variable names into an allowlist using the --allow-env flag as shown below. Any variables not included in the allowlist will be inaccessible through process.env.

# Limited access
node --experimental-permission

# Full access
node --experimental-permission --allow-env

# Single name
node --experimental-permission --allow-env=HOME 

# Multiple names
node --experimental-permission --allow-env=HOME,PORT

3. How do the others do?

A comparable example is deno, which has the same as this proposed one.

--allow-env=<VARIABLE_NAME> Allow environment access for things like getting and setting of environment variables. Since Deno 1.9, you can specify an optional, comma-separated list of environment variables to provide an allow-list of allowed environment variables.


Below are a summarized thoughts of the opposing perspectives discussed so far. Please let me know if there are any omissions or inaccuracies.

1. Needed?

Accessing to environment variables is not inherently dangerous. There is also a question as to why this should be prevented and informed. Regarding the allowlist, there is already a universal way to selectively pass environment variables to any program, which is much easier and better than the new flag provided.

2. How to do?

Since environment variables are just a list of names passed to a process, users can control it in the shell as shown below.

# linux bash
env -i HOME=$HOME PORT=$PORT node

# windows prompt
cmd /c "set HOME=%HOME% && set PORT=%PORT% && node"

Alternatively, we can rely on package manager to only selectively pass environment variables to child processes.

(daeyeon: I guess we could use cross-env to do this.)

{
  "scripts": {
    "dev": "cross-env HOME=$HOME PORT=$PORT node <program>"
  }
} 

3. How do the others do?

There is a concern about the code complexity. Deno is designed to have a built-in and useful permission system from the beginning, which is not the case with Node.js. Since the easy way to control it externally exists, we need to consider the worth of the complexity. Plus, catching up with questionable features shouldn't be our goal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions