Skip to content

fix: validate environment variable key names before writing to .env files#38

Closed
0x-SquidSol wants to merge 1 commit intonullxnothing:mainfrom
0x-SquidSol:fix/sanitize-env-variable-key-names
Closed

fix: validate environment variable key names before writing to .env files#38
0x-SquidSol wants to merge 1 commit intonullxnothing:mainfrom
0x-SquidSol:fix/sanitize-env-variable-key-names

Conversation

@0x-SquidSol
Copy link
Copy Markdown

Summary

  • writeEnvVar and addEnvVar accepted arbitrary key names without validation
  • A key containing shell metacharacters (e.g. KEY=$(cmd)) could cause command injection when the .env file is sourced by a shell
  • Both functions now validate keys against the POSIX standard (/^[A-Za-z_][A-Za-z0-9_]*$/) and reject invalid names

Test plan

  • Add an env var with a valid name (e.g. MY_KEY) — verify it works
  • Attempt to add an env var with $(cmd) in the name — verify it throws
  • Run pnpm run typecheck — passes clean
  • Run pnpm run test — 234/234 pass (10 pre-existing failures unrelated)

…iles

writeEnvVar and addEnvVar accepted arbitrary key names without
validation. A key containing shell metacharacters (e.g. KEY=$(cmd))
could cause command injection when the .env file is sourced. Both
functions now reject keys that don't match the POSIX standard for
environment variable names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nullxnothing
Copy link
Copy Markdown
Owner

Closed as superseded by #75, which reapplies the corrected security hardening on top of current main. This avoids merging stale/conflicted branches and preserves the fixes with passing CI/CodeQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants