Security: Command injection risk in global teardown process-kill commands#5299
Conversation
The teardown script builds shell commands with `BACKEND_PORT` from environment variables and passes them to `execSync` (`pgrep -f 'e2e:${BACKEND_PORT}'` / `pkill -f 'e2e:${BACKEND_PORT}'`). If `BACKEND_PORT` is attacker-controlled (e.g., in CI or local env), shell metacharacters or quote-breaking payloads could inject arbitrary commands.
Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
|
norman-abramovitz
left a comment
There was a problem hiding this comment.
Thanks for the patch. The code change itself is clean — execFileSync with argv avoids shell interpretation entirely, and the /^\d{2,5}$/ guard adds a nice defense-in-depth check. It's a straightforward hygiene improvement and I'm fine merging it on those grounds.
That said, I'm not going to characterize this as a security issue. BACKEND_PORT is read from the environment of a developer-invoked test-teardown script — anyone able to set it already has local code execution and doesn't need an injection vector. No trust boundary is crossed, no untrusted input reaches this path, no production code runs this file. This is a linter pattern-match, not a vulnerability — please label future contributions as hygiene rather than severity-rated security issues.
Dismissing — posting as comment instead.
|
Thanks for the patch. The code change itself is clean — That said, I'm not going to characterize this as a security issue. |
Summary
Security: Command injection risk in global teardown process-kill commands
Problem
Severity:
High| File:e2e/global-teardown.ts:L16The teardown script builds shell commands with
BACKEND_PORTfrom environment variables and passes them toexecSync(pgrep -f 'e2e:${BACKEND_PORT}'/pkill -f 'e2e:${BACKEND_PORT}'). IfBACKEND_PORTis attacker-controlled (e.g., in CI or local env), shell metacharacters or quote-breaking payloads could inject arbitrary commands.Solution
Avoid shell interpolation. Use
spawn/execFilewith argument arrays and strict validation ofBACKEND_PORT(e.g.,/^\d{2,5}$/). Example: validate port, then callpgrep/pkillwith args['-f',e2e:${port}]without invoking a shell.Changes
e2e/global-teardown.ts(modified)