fix(env): shell-quote values written to env.sh to prevent injection#40
Open
hobostay wants to merge 1 commit into
Open
fix(env): shell-quote values written to env.sh to prevent injection#40hobostay wants to merge 1 commit into
hobostay wants to merge 1 commit into
Conversation
generateEnvFile built `export KEY="VALUE"` with no escaping. env.sh is sourced from every team member's shell profile, and its values come from the team repo's env/env.yaml — so a value containing `"`, `$`, a backtick, or `\` either breaks the sourced script or runs injected commands. Example: value `x"; echo PWNED #` produced export INJECT="x"; echo PWNED #" which executes `echo PWNED` on source. Single-quote each value (encoding embedded single quotes as `'\''`) so all metacharacters are taken literally. Added a regression test covering quotes, `$`, and embedded single quotes; updated existing assertions to the new format. `npm test` (1436 tests) and `tsc --noEmit` pass. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EnvHandler.generateEnvFilewrites~/.teamai/env.shwithexport KEY="VALUE"lines and no escaping of the value. This file is sourced from every team member's shell profile (seepullItem→generateShellBlock/injectShellProfile), and the values originate from the team repo'senv/env.yaml. A value that contains",$, a backtick, or\will either break the sourced script or run injected commands.Problem
src/resources/env.ts:Concrete example — a value
x"; echo PWNED #produces:When any member runs
teamai pulland later opens a shell, sourcingenv.shexecutesecho PWNED. Less maliciously, a perfectly normal value containing$(e.g. a connection string) gets variable-expanded, and a value containing"truncates the line and yields a broken/unclosed quote that errors on source.Fix
Single-quote each value so shell metacharacters are taken literally, encoding an embedded single quote as the standard
'\''sequence (works in bash/zsh/sh):Verified end-to-end — sourcing the generated file stores every value literally with no injection:
Tests
generateEnvFile/pullItemassertions to the single-quote output format.should shell-quote values containing shell metacharacters) covering",$, and an embedded single quote.npm test→ 1436 passed | 4 skipped;tsc --noEmit→ clean.Notes
env.yamland are left as-is (unchanged behavior).~/.teamai/envKEY=VALUEbackup file (loadEnvFilecompatibility) is a different code path and intentionally untouched.