vercel/turborepo
Command injection via unescaped git ref in turbo-ignore
Summary
Context: The
turbo-ignorepackage is a CLI tool used in CI/CD pipelines (especially on Vercel) to determine if a build should proceed based on whether a workspace or its dependencies have changed.Bug: The
getComparison.tsfile contains a command injection vulnerability where unescaped user input is interpolated directly into shell commands executed viaexecSyncandexec.Actual vs. expected: The code uses string interpolation to build shell commands with user-controlled input (the
fallbackCLI argument andVERCEL_GIT_PREVIOUS_SHAenvironment variable) without any sanitization or escaping. The expected behavior is to safely validate git references and use them in commands without allowing arbitrary command execution.Impact: An attacker who can control the
fallbackargument or theVERCEL_GIT_PREVIOUS_SHAenvironment variable can execute arbitrary shell commands with the privileges of the CI/CD process, potentially leading to credential theft, code injection, or supply chain compromise.
Code with bug
In getComparison.ts
In ignore.ts
Example
Run:
Flow:
The
fallbackvalue is used ascomparison.refwithout sanitization.The command constructed in
ignore.tsbecomes:The shell interprets this as multiple commands, executing
touch /tmp/pwned.
Result:
/tmp/pwnedis created, demonstrating arbitrary command execution via the fallback path.
Recommended fix
Use non-shell APIs with argument arrays to avoid interpolation:
Alternatively, strictly validate refs against an allowlist pattern before use.
