fix: close the residual bypasses behind issues #52 and #49 - #56
Merged
Conversation
e28d083 patched the literal PoC strings from both issues but not the underlying bug class. Both were still exploitable with a one-character variation on the original reports. #52: _MARKER_LEFT_BOUNDARY in wrap.py used (?<=\S), which still glued the next chain marker onto a segment ending in whitespace (trailing space, tab, or a blank/indent-only line), leaking the raw marker into output and collapsing segment attribution exactly as originally reported. Changed to (?<=[^\n]) to cover every same-line character. #49: iter_unquoted (src/shell_syntax.py) only honored backslash escapes inside double-quoted regions. An unquoted " or \' — an ordinary, well-formed shell token — was misread as opening a quoted region that never closes, so the scanner swallowed everything after it, including a smuggled newline or &. This blinded has_unquoted_newline, has_unquoted_background_operator, has_output_redirection, and the dangerous-construct check simultaneously, since they all share this scanner. Fixed at the source: a backslash outside quotes is now consumed as a literal escape pair before quote detection. Also closes the issue's three remaining sub-claims: - re.MULTILINE added to both exclusion pattern lists (defense in depth) - wrap.py now re-validates is_compressible() itself before applying its chain-rewrite, instead of trusting the hook's verdict unconditionally - a new is_destructive() check withholds permissionDecision: allow for irreversible commands (force-push, git reset --hard, kubectl delete, terraform apply/destroy, docker rm/rmi/system prune, rm -rf), so they fall through to Claude Code's normal permission flow instead of being auto-approved New tests/test_shell_syntax.py covers iter_unquoted and its consumers directly. tests/test_hooks.py gains regression coverage for the marker boundary, the classifier bypass, wrap.py's re-validation, and is_destructive(). Full suite: 1364 passed, 0 failed.
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.
e28d083 patched the literal PoC strings from both issues but not the underlying bug class. Both were still exploitable with a one-character variation on the original reports.
#52: _MARKER_LEFT_BOUNDARY in wrap.py used (?<=\S), which still glued the next chain marker onto a segment ending in whitespace (trailing space, tab, or a blank/indent-only line), leaking the raw marker into output and collapsing segment attribution exactly as originally reported. Changed to (?<=[^\n]) to cover every same-line character.
#49: iter_unquoted (src/shell_syntax.py) only honored backslash escapes inside double-quoted regions. An unquoted " or ' — an ordinary, well-formed shell token — was misread as opening a quoted region that never closes, so the scanner swallowed everything after it, including a smuggled newline or &. This blinded has_unquoted_newline, has_unquoted_background_operator, has_output_redirection, and the dangerous-construct check simultaneously, since they all share this scanner. Fixed at the source: a backslash outside quotes is now consumed as a literal escape pair before quote detection.
Also closes the issue's three remaining sub-claims:
New tests/test_shell_syntax.py covers iter_unquoted and its consumers directly. tests/test_hooks.py gains regression coverage for the marker boundary, the classifier bypass, wrap.py's re-validation, and is_destructive(). Full suite: 1364 passed, 0 failed.
What
Why
How
Checklist
ruff check .passesruff format --check .passespython3 -m pytest tests/ -vpasses (all 207+ tests)