denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.98k stars 5.23k forks source link

Pass a wildcard suffix to --allow-env #24847

Open ari-becker opened 1 month ago

ari-becker commented 1 month ago
MYAPP_HELLO=world deno run '--allow-env=MYAPP_*' <(echo 'console.log(Deno.env.get("MYAPP_HELLO"))')

This should permit access to MYAPP_HELLO instead of refusing access.

Allowing this will make the list of permitted environment variables more maintainable, while ensuring that environment variables from the host system ($USER, $HOME, $PATH, etc.) remain blocked. This is similar to features like Vite's support for environment variables, where only environment variables with a given prefix (VITE_) will be bundled in, thus providing protection against unintended environment variables being allowed.

Radiergummi commented 2 weeks ago

This would be amazing. Prefixing environment values with an app identifier is good practice anyway, so that'd make both the list of permissions more manageable, and promote conventions around variable naming.