Repository navigation
wrangler dev: secrets from --env-file are inherited by the workerd process environment
#16197
schalkneethling
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
In local dev, the secret values that Wrangler loads from
--env-file(or.dev.vars/.env) end up in the environment of theworkerdprocesses that Miniflare starts. Workers receive bindings through the Miniflare configuration, not through theworkerdprocess environment, so this copy looks unnecessary. It makes the values visible wherever a process environment is visible, for exampleps -Efor the same user, and process inspection tools.Versions
wrangler4.147.0,miniflare5.20261001.0-alpha, macOS 27.0.1, Node 24.21.0.How it happens
process.env = loadDotEnv(resolvedEnvFilePaths, { includeProcessEnv: true, silent: true })(wrangler-dist/cli.js, during argument checks fordev). Withsecrets.requiredconfigured, it logs "Using secrets defined in process.env".Runtime.updateConfigstartsworkerdwithenv: { ...process.env, TZ: "UTC", FORCE_COLOR, ...options.runtimeEnv }(miniflare/dist/src/index.js).So every value from the env files becomes part of
workerd's environment.Reproduction
"secrets": { "required": ["MY_SECRET"] }and putMY_SECRETin an env file, or pass it with--env-file. For example, varlock'svarlock-wrangler devpasses it through a FIFO, so it is never on disk.wrangler dev.ps -E -p <workerd pid> -ww -o command=contains the secret value. The Worker also receives it correctly asenv.MY_SECRET.Suggestion
Start
workerdwith an allowlisted environment (for examplePATH,HOME,TZ,FORCE_COLOR, proxy and certificate variables, plusoptions.runtimeEnv) instead of the fullprocess.env. Or at least remove the keys that Wrangler loaded from env files. I don't know which variablesworkerdrelies on, so the allowlist needs input from the maintainers.Impact
Low: local development only, and on most systems only the same user or root can read another process's environment. It removes one more copy of each secret, though. Tools that are careful to keep secrets off disk and out of process arguments (such as varlock's FIFO) currently lose that guarantee one step later.
All reactions