Repository navigation
fix(guardrails): stop judging gh --attach source paths as posted machine paths under Bash - #16066
Conversation
…-content Add stay-quiet cases for --attach operands whose directory is a home path or the project root, which gh never posts, and deny cases for every nearby shape that does post a machine path or secret: alt text, the base name, a body or body file, look-alike flags, an --attach= word taken as another flag's value, and operands the shell would expand. The quiet cases and the adjacent-alt deny case fail on the current hook. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ine paths gh uploads an --attach file and posts only its alt text (after a `#`) or its base name, never its directory, so block-github-post-content refused valid calls whose attached file sat under a home directory or the project root. The shared parser now keeps a literal --attach operand of gh pr|issue as its own body kind, `attach`, and the path pass judges only the text after its first `#` and its base name. The secret pass and block-fix-request-post still read the whole operand. An operand the shell could expand, or one after a dash flag without `=` (which may take the word as its value, as in `--body --attach=X`), is still judged whole. Closes #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tution A backtick substitution in an --attach operand can split it into a posted --body; the operand must stay judged whole. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at run time An empty variable, an IFS split, a brace expansion, an empty "$@" or substitution, and on PowerShell $null or a dropped '' can leave a value-taking flag right before `--attach=<path>`, which then posts the whole word. Also cover a bool flag before --attach, a glob in the operand, the `=` and `-` exemptions, and the joined form with a home path in its alt text. The eight vanishing-word cases fail on the current hook. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A word before `--attach=<path>` that vanishes or splits at run time (an empty variable, an IFS split, a brace expansion, an empty "$@" or substitution, PowerShell $null or a dropped '') can leave a value-taking flag right before the joined word, so gh posts the whole word. Capture a joined operand only when the word before it is literal, and non-empty on PowerShell; otherwise it is judged whole as before the fix. The spaced form is unchanged: there the flag takes `--attach` and the operand is a positional argument gh never posts. Correct the parser comment on `--body --attach X`, and describe the final rule in the guard header, README row 99 and the changelog fragment. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under PowerShell's legacy native argument passing an embedded double quote is not escaped, so it can split a word or join later words, the attach operand included, into one posted value. Cover a quote in the body before a joined attach, in a spaced and in a joined operand, and in an earlier word of the segment. The four cases fail on the current hook. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uble quote Under PowerShell's legacy native argument passing (Windows PowerShell 5.1, or $PSNativeCommandArgumentPassing = Legacy) an embedded double quote is not escaped, so a word holding one can split, or join later words, the attach operand included, into one posted value. On PowerShell, keep no --attach operand apart in a gh pr|issue segment where any word holds a double quote; every word is then judged whole, as before the fix. Name the rule in the parser comment, the guard header, README row 99 and the changelog fragment. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
PowerShell's argument passing to a native command (quoting, empty strings, the stop-parsing token) can change the words gh receives in ways the guard's tokenizer cannot model, so under the PowerShell tool no --attach operand is kept apart any more: every word is judged whole, as on main. The Bash tool's exemption is unchanged. Remove the machinery only PowerShell capture used: the double-quote segment flag, the non-empty check before a joined operand, the PowerShell `,`, `(` and `@` branch of the literal test, and the backslash base-name split. The PowerShell quiet cases become deny cases that pin the fail-closed behavior, with four more PowerShell shapes. Refs: #15979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shell-portability check reads the fixture path's `\w` as a GNU-only regex escape and refuses the push. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Lane run report
Failed GitHub API calls
|
|
claude-security-review reviewed Security review: no security issues foundcritical-findings: 0 I read every hunk of all 5 changed files in the full diff. I also read the surrounding code of the changed hook, What changes. Under the Bash tool, What I checked:
The README row and the Spend. None beyond this review run. |
|
claude-review reviewed Code review: no findingsI read every hunk of all 5 changed files. To check the change in context, I also read the unchanged code around it: What I checked
PR context
Spend: none. The change adds no CI, model or schedule use. Verifier dropped 0 of 0 candidates. |
Refs: #15979
Summary
block-github-post-contentrefusedgh pr|issue create|comment|edit ... --attach <local path>when the attached file sat under a home directory or the session's project root. It reported the source path as a machine path that "would be posted". gh posts only the alt text or the file name. Local gh 2.103.3,gh issue create --helpandgh pr comment --help: "Alt text for an image follows the path after#, as in--attach './login.png#The login error state'. Without it the filename is used."gh pr review --helplists no--attachflag.This change exempts the source path under the Bash tool only. Under the PowerShell tool every
--attachoperand is still judged whole, exactly as on main. See Remaining.Fix
plugins/guardrails/lib/github-post/github-post-body.sh: under the Bash tool, a literal--attachoperand of agh pr|issuesegment goes to a new list,GHPOST_ATTACH, and comes out ofghpost::bodiesas a new body kind,attach, in both the whole-command and the word branches. It stays inGHPOST_BODY, so the secret pass andblock-fix-request-poststill read the whole operand.$, backtick,{or glob character (*?[).--attachis a dash flag without=. pflag takes the next word as a flag's value even when it starts with-, so--body --attach=<home>/x.pngposts--attach=<home>/x.pngas the body.--attach=<v>is also captured only when the word before it is itself literal. A word that vanishes or splits at run time (an empty variable,$IFS, a brace, an empty"$@", backtick or$( )) can leave a value-taking flag right before the joined word, which then posts it.--attach, that flag takes--attachas its value, and the operand becomes a positional argument, which gh refuses (gh pr comment [<number> | <url> | <branch>]takes one) or reads as the selector, posting it neither way.Legacy,Standard, andWindows." It also says "PowerShell 7.3 changed the way the command line is parsed for native commands" and "The new behavior is a breaking change from the Windows PowerShell 5.1 behavior." Which exact words gh receives in each mode for the shapes the reviews found is UNVERIFIED by a real PowerShell run.--attachstate is alocalofghpost::segment, so it never carries into the next segment.plugins/guardrails/hooks/block-github-post-content.sh: the path pass judges anattachtext as the text after its first#plus its base name, split on/. The headers are updated: MACHINE PATHS, and the fail-closed exceptions.plugins/guardrails/README.mdrow 99 describes the Bash-only exemption and the PowerShell whole-word judgment..changes/guardrails/fix-guardrails-attach-paths-15979-719889a2.md:bump: patch,### Fixed.plugin.jsonis unchanged.Where this differs from the issue's Plan:
=. Disabling it fails 4 deny cases (--body '--attach=...',--body --attach=...,-b --attach=...,--title --attach=...).$IFSsplit, a brace expansion, an empty"$@", an empty backtick substitution and an empty$( ).#and the base name are judged. The Plan judged only the alt text when a#was present. With a#after the last/, the default alt text holds text from before the#./only. On Linux gh's base name of a backslash<win home>\x.pngis the whole string, and gh posts it as the default alt text.Remaining false positives, all failing closed:
--attachoperand under the PowerShell tool;--draft --attach X);$, a backtick or{;--attach=<v>after a non-literal word (the spaced form after"$X"passes);Verification
The branch is based on origin/main
709e2b319f. Every line the issue cites at999cb91c1bstill matched.Run with
env --chdir=<worktree> scripts/run-test-file.sh <file>on Linux (WSL2), bash 5:plugins/guardrails/hooks/block-github-post-content.test.sh: PASS=186 FAIL=0 on the branch head.quiet: attach ...case ordeny: attach adjacent alt home path.deny: PowerShell attach judged whole: ...cases, run against the previous head's code.quietcases (project root under/tmp) were red on main, which provesCLAUDE_PROJECT_DIRreaches the hook.$IFSdeny cases (run on an earlier head; the array case is PowerShell and now refuses because PowerShell is judged whole, not because of the literal check).plugins/guardrails/hooks/block-fix-request-post.test.sh: PASS=316 FAIL=0 on the branch and on agit archiveextract of main in the same checkout. The hook and its test are unchanged.shellcheck -xis clean on the three shell files.typosis clean on all changed files.scripts/check-changelog-fragments.sh --checkand--check-required origin/mainpass.Before/after measurement: the issue's Baseline script, with its scratch kept in the output directory. It was run on main (extract) and on the branch head in one session on the same host (Linux, hyperfine 1.21.0, 5 runs, medians in ms):
On this host main's r1 count is 25, where the issue's Windows count is 24. The Windows wall-time numbers in the issue were not rerun.
Runner portability:
Done-when status for the final code:
--body "$X" --attach <home>/x.pngexits 0 under Bash.#exits 2.<win home>\...\x.pngoperand exits 2, not 0; it is pinned as a deny case.bash scripts/check-changelog-fragments.shwith no argument exits 2 with a usage line, so it was run as--checkand--check-required origin/main; both pass./code-metricscomplexity,/code-metrics:audit-duplicationand/simplifypasses were not run./review:quality-gatecode and security modes were not run. Three independent review rounds ran on earlier heads; their findings are addressed and tested, but no quality-gate report exists.Remaining
The PowerShell half of AC8 (a single-quoted
<win home>operand exits 0), and with it the issue's PowerShell evidence cases p2 and p2a, are not delivered. Under the PowerShell tool an--attachoperand is still judged whole, as on main. Three review rounds each found a PowerShell shape that would post a home path. The classes were:The guard's tokenizer cannot model PowerShell's passing reliably, so the exemption was withdrawn there.
AC16's metrics, duplication and
/simplifypasses, and AC17's quality gate, were not run.Related
🤖 Generated with Claude Code
session: GitHub Support