Repository navigation
Agent hooks read shell redirections: 2>&1 no longer ends the command and hides the flags after it (#154) - #155
Merged
Merged
Conversation
A pure move, no behaviour change: USER_ONLY_VARS and envFor, with their doc comments, go verbatim from src/shellwords.ts (over its size limit) into the new src/user-env.ts, which imports only the Invocation type from shellwords.ts. The importers (hooks/agents.ts, explain.ts and three tests) import envFor from user-env.ts directly; nothing else used it. (cherry-picked from 5322307; its hunks for two tests that do not exist on this branch were dropped) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#154) Failing on its own, before the fix. findInvocations reads `2>&1` as the end of the command at its `&`, so `az 2>&1 group list --subscription other` is checked as `az 2>`, and it keeps `>`, `out.txt` and `2>/dev/null` as arguments. The new tests cover every bash and PowerShell redirection form, with the target attached and separate, before the command word, between and after the flags; that && || ; | |& and & still split commands; heredocs, process substitution and a command substitution in the target; the cases where the word is kept (x2>out, "2">out, \2>out, 2&>out, 12>out); and wrong-pin controls through the Claude Code hook for az (Bash and PowerShell tools) and vercel, with matching pins still allowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…154) The tokenizer split `2>&1` at its `&`, as if `&` ended the command, so everything after it was lost: `az 2>&1 group list --subscription other` was checked as `az 2>` against the default subscription. It also kept redirection words as arguments, where they could pass for a command word, a deploy path or a flag value. The new src/redirections.ts recognises the operators (bash: > >> < >| <> >& <& &> &>>; PowerShell's have the same shapes) and the stream number written right before one (a single digit, or PowerShell's *). The tokenizer drops the stream number, the operator and its target word, attached or after spaces, wherever they appear in the command, before the command word too. A command substitution in the target still runs and is still checked. && || ; | |& and & split commands as before, and <( and >( stay process substitutions. Where the line could mean either, the word is kept: x2>out, "2">out and \2>out pass their word as bash does, 2&>out passes 2, and 12>out keeps 12 (bash reads 12 as a stream, PowerShell passes `12>out` as one argument). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <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.
Closes #154. Milestone 1.2.0: the owner moved it in on 2026-10-25, so it ships Thursday 2026-10-29.
The bypass
In agent hooks and
cloudpin explain,findInvocationssplit2>&1at the&, as if&ended the command.az 2>&1 group list --subscription <another subscription>was read asaz 2>, and the verdict was "the account matches the pin". This was checked against a real az login. Redirection words also stayed in the arguments (> out.txt,2>/dev/null). The shell wrappers were never affected.The fix
envForandUSER_ONLY_VARSintosrc/user-env.ts. It's needed becausesrc/shellwords.tswas over the 5,000-token cap on main. The moved file is byte-identical to 5322307's, so Windows: cloudpin's own variables and the read-only check fold names; Wrangler's login folder per platform (#136) #152 will merge cleanly later. Two hunks for tests that exist only on Unknown Cloudflare account values block, and Windows variable names are case-insensitive (#119) #135's branch were dropped. Test counts are unchanged.src/redirections.ts, withredirection()(operator length) andisStream()(stream number). The tokenizer drops the stream number, the operator and its one target word, attached or separate, anywhere in the command, before the command word included. The&in>&,<&or&>no longer splits the command.>,>>,>|,<,<>,>&m,<&m,&>,&>>, and PowerShell's*>andn>&1.&&,||,;,|,|&and&still split commands. Here-docs, here-strings and process substitution still work.bash 2>&1 <<EOFhid the here-doc's calls.Tests
The tests are in the new file
test/shellwords-redirections.test.ts, 79 of them. They were committed failing first: 69 failed.runHook(AGENTS.claude)with the real azure and vercel providers and a fakeExec:--subscription otherwith the redirection in different places are denied;vercel 2>&1 deploy --scope sideis denied, and with--scope acmeit's allowed.cloudpin explaincheck on the build. Both2>&1placements are now stopped, andaz group list 2>&1with the matching pin is still allowed.Left open
vercel deploy <(x) --scope otherloses--scope other. This existed before this change; it gets its own issue.word>file(no space) as one argument, but this parser follows bash and splits it. A CLI would then get an invalid value and fail.0<<EOF) stays as the argument0. That errs on the side of checking.🤖 Generated with Claude Code