fix(terminal-security): prevent newline bypass in command validation #8512
+266
−1
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
Fixes a security vulnerability where an attacker could bypass the terminal command allow-list by using newline characters (
\n,\r\n,\r) as command separators.The Vulnerability
The
shell-quotelibrary treats literal newline characters as whitespace rather than command separators. This caused multiple newline-separated commands to be evaluated as a single command, allowing dangerous commands to be hidden after safe ones.Attack Examples
ls\nopen -a Calculator→ Bypassed toallowedWithoutPermission(should require permission)ls\nnpm install malicious→ Bypassed toallowedWithoutPermission(should require permission)echo hello\nopen -a Calculator→ Bypassed toallowedWithoutPermission(should require permission)The Fix
The solution splits input on line breaks (
/\r?\n|\r/) before parsing with shell-quote, evaluating each line independently and returning the most restrictive policy.Changes
evaluateTerminalCommandSecurity()to split on newlines before parsing\n,\r\n,\r)Security Impact
✅ Fixed: Newline bypass for medium/high-risk commands
✅ Maintained: Critical commands (sudo, rm -rf /) still properly blocked
✅ Maintained: Existing security checks for semicolons, pipes, etc.
Testing
All 224 tests pass, including:
This agent session was co-authored by nate and Continue.
Summary by cubic
Prevents a newline-based bypass in terminal command validation by splitting input on line breaks and evaluating each line separately. Applies the most restrictive policy across lines to stop hidden dangerous commands.