hook: refuse a quoted command string passed through a login shell - #508
Conversation
`sudo -i` starts the target user's login shell, and that shell parses the remaining arguments a second time. The quoting the first parse consumed is gone by then, so the command string is re-split and its first word becomes the whole command. A handoff script died this way in a user's terminal. Reproduced on a real host, one variable apart: `sudo -u demo -H bash -lc '<body>'` prints the body's output, and the same line with `-i` gives `bash: line 1: set: -c: invalid option`. Newlines are not the trigger, which is what the first reading of the failure got wrong. A multi-line body survives ssh and survives sudo without `-i`. Backtested over 37,015 real Bash commands: 6 hits, all the broken shape. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KU2pPKob4MJ1NqjsfTNyYJ Change-Id: Iacc7d62317959adeb953d4fef0bc9dc222a37430
This was referenced Sep 12, 2026
Owner
Author
|
This pull request is part of a Mergify stack:
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_b4f81974-f0cc-47e1-bd46-3f4d0b6ad249) |
This was referenced Sep 12, 2026
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.
sudo -istarts the target user's login shell, and that shell parses theremaining arguments a second time. The quoting the first parse consumed is
gone by then, so the command string is re-split and its first word becomes
the whole command. A handoff script died this way in a user's terminal.
Reproduced on a real host, one variable apart:
sudo -u demo -H bash -lc '<body>'prints the body's output, and the same line with-igivesbash: line 1: set: -c: invalid option.Newlines are not the trigger, which is what the first reading of the
failure got wrong. A multi-line body survives ssh and survives sudo without
-i.Backtested over 37,015 real Bash commands: 6 hits, all the broken shape.
Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01KU2pPKob4MJ1NqjsfTNyYJ
Depends-On: #507
Note
Low Risk
Adds an optional PreToolUse gate on Bash commands with fail-open error handling; may block rare legitimate sudo -i + quoted -c patterns until rewritten.
Overview
Adds a new Claude PreToolUse (Bash) hook,
remote-payload-collapses, that blocks commands where a quoted command string is passed throughsudo -i,su -, orsu -l. The login shell re-parses arguments after the first parse consumed quoting, so the payload is re-split and often breaks (e.g.bash -lc '<body>'vs the same line with-i).Detection is text-only (
detect.collapse_risk): login-shell pattern, a carried interpreter (bash,-c, etc.), and quotes in the tail; heredocs are stripped so stdin/file patterns stay allowed. On match the hook exits 2 with remediation (drop-i, or scp + run by path); malformed JSON and detector errors fail open.install.shsymlinks the hook and mergesinstall_claude_hook.pyinto~/.claude/settings.json. README /docs/ecosystem.mddocument it; unit tests cover fire/silent fixtures and install wiring.Reviewed by Cursor Bugbot for commit d76e1e5. Bugbot is set up for automated code reviews on this repo. Configure here.