fix(security): remove shell=True from generator drift runner (LED-713)#3
Merged
fix(security): remove shell=True from generator drift runner (LED-713)#3
Conversation
delimit_security_audit flagged core/generator_drift.py:104 for subprocess(shell=True) — a real command injection surface, since the generator_command input flows from the caller's workflow file straight to a shell. Fix: - Parse regen_command with shlex.split and run with shell=False - Reject shell metacharacters (&, |, ;, >, <, `, $) with a clear error message pointing users at script files for chaining/env vars/etc. - Handle FileNotFoundError explicitly for missing executables - Handle shlex.split ValueError for unparseable commands - Reject empty commands Also adds tests/test_generator_drift.py (17 tests): - 8 injection-guard tests (chain, pipe, redirect, backtick, $(), ;, empty, unparseable) - 3 happy-path tests (simple command, drift detection, workspace restore) - 4 error-handling tests (missing artifact, missing executable, exit code, timeout) - 2 formatter tests Verified: - All 88 prior tests still passing, 105 total (88 existing + 17 new) - Real agentspec 'pnpm run schema:export' still works (8.1s) - delimit_security_audit now clean (0 findings) This fix makes the v1.9.0 release candidate safe to ship. The previously-rolled-back release bundled the same code with the shell=True bug. Co-Authored-By: Claude Opus 4.6 (1M context) <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
Why this matters
This is the first gate-driven fix in the v1.9.0 re-release. The previous attempt at v1.9.0 was rolled back because the deploy gates (`security_audit`, `test_smoke`, `changelog`, `deploy_plan`) were skipped. Running them properly caught this bug before it shipped.
Test plan
What changed in generator_drift.py
Before:
```python
result = subprocess.run(
regen_command,
shell=True, # ← command injection surface
...
)
```
After:
```python
argv = shlex.split(regen_command)
Reject shell metacharacters — force script files for chaining
if any(ch in token for token in argv for ch in "&|;><`$"):
return DriftResult(error="generator_command contains shell metacharacters...")
result = subprocess.run(argv, shell=False, ...)
```
Users needing shell features (chaining, env vars, redirection) should point `generator_command` at a script file instead of inline-chaining — documented in the rejection error message.
🤖 Generated with Claude Code