-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING(dotenv): Fix dot env permissions #3578
Conversation
Any ideas why the linter is failing? Also failing locally for me, but I'm not sure how to fix it. |
|
* looked up. This allows to permit access to only specific Env variables with | ||
* `--allow-env=ENV_VAR_NAME`. | ||
*/ | ||
restrictEnvAccessTo?: StringList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this option only in typing in a few versions to prevent immediately breaking users code (in type checks)
* Load environment variables from a `.env` file. | ||
* Load environment variables from a `.env` file. Loaded variables are accessible | ||
* in a configuration object returned by the `load()` function, as well as optionally | ||
* exporting them to the process environment using the `export` option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice clean up and fix!
Addresses #3572
Headline changes
restrictEnvAccessTo
configuration optionOverview
This is a breaking change, primarily to remove the
restrictEnvAccessTo
configuration option. To allow expansion of.env
variables to use values from the process environment, the original implementation read the entire process environment into memory. This mean all users of dotenv required the--allow-env
permission. Accessing all process variables was undesirable if you only needed to expand a single env variable, sorestrictEnvAccessTo
was added to restrict which env variables dotenv had access to and allow the granular--allow-env=SOME_VAR
to work properly. This setup deviates away from how Deno handles permissions.This change now allows for per-env-var access with no code configuration required and if you don't export any variables or expand any process variables then no
--allow-env
permissions are needed at all. The below examples show before and after permission handling:Permission example 1
#.env HELLO=world
Before change: Run with
deno run --allow-read --allow-env mod.ts
After change: Run with
deno run --allow-read mod.ts
Permission example 2
Before change: Run with
A=world deno run --allow-read --allow-env mod.ts
(full env access still required)After change: Run with
A=world deno run --allow-read --allow-env=A mod.ts
(granular access allowed)Permission example 3
Before:
Run with
A=world deno run --allow-read --allow-env=A mod.ts
(granular access only works with code grant toA
viarestrictEnvAccessTo
)After change:
Run with
A=world deno run --allow-read --allow-env=A mod.ts
(no code change required for granular access)Bug fix
When expanding a process environment var who value was blank, the existing code was setting the configuration value to undefined rather than empty string.
Before:
Run with
A= deno run --allow-read --allow-env mod.ts
yields:After change:
Run with
A= deno run --allow-read --allow-env=A mod.ts
yields:Additional consideration
As this is a breaking change, it may be desirable to consider #3561 as well, which would also be a breaking change to dotenv. However, as there is no feedback on that proposal to date no PR for that change has been progressed.