Skip to content

fix(guardrails): stop judging gh --attach source paths as posted machine paths under Bash - #16066

Merged
kyle-sexton merged 9 commits into
mainfrom
fix/guardrails-attach-paths-15979
Nov 14, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
fix/guardrails-attach-paths-15979

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #15979

Summary

block-github-post-content refused gh 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 --help and gh 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 --help lists no --attach flag.

This change exempts the source path under the Bash tool only. Under the PowerShell tool every --attach operand 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 --attach operand of a gh pr|issue segment goes to a new list, GHPOST_ATTACH, and comes out of ghpost::bodies as a new body kind, attach, in both the whole-command and the word branches. It stays in GHPOST_BODY, so the secret pass and block-fix-request-post still read the whole operand.
    • "Literal" means no $, backtick, { or glob character (*?[).
    • Neither form is captured when the word before --attach is a dash flag without =. pflag takes the next word as a flag's value even when it starts with -, so --body --attach=<home>/x.png posts --attach=<home>/x.png as the body.
    • A joined --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.
    • The spaced form needs no check on the word before it. If a vanished word leaves a flag right before --attach, that flag takes --attach as 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.
    • Under the PowerShell tool nothing is captured, and every word is judged whole as on main. Microsoft's about_Parsing documents several passing modes for native commands: "The valid values are Legacy, Standard, and Windows." 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.
    • The pending---attach state is a local of ghpost::segment, so it never carries into the next segment.
  • plugins/guardrails/hooks/block-github-post-content.sh: the path pass judges an attach text 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.md row 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.json is unchanged.

Where this differs from the issue's Plan:

  1. The previous-word rule has two parts.
    • No capture after a dash flag without =. Disabling it fails 4 deny cases (--body '--attach=...', --body --attach=..., -b --attach=..., --title --attach=...).
    • A joined operand is captured only after a literal word. Without that, 6 Bash deny cases exited 0: an empty variable, an $IFS split, a brace expansion, an empty "$@", an empty backtick substitution and an empty $( ).
  2. Both the text after the first # 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 #.
  3. The base name splits on / only. On Linux gh's base name of a backslash <win home>\x.png is the whole string, and gh posts it as the default alt text.
  4. Glob characters count as non-literal.
  5. No exemption under the PowerShell tool. The Plan exempted PowerShell operands too.

Remaining false positives, all failing closed:

  • every --attach operand under the PowerShell tool;
  • under Bash, an operand that follows a bool flag (--draft --attach X);
  • under Bash, an operand holding a glob character, $, a backtick or {;
  • under Bash, a joined --attach=<v> after a non-literal word (the spaced form after "$X" passes);
  • a Windows Git Bash backslash operand;
  • a body reference to the attached file's absolute path.

Verification

The branch is based on origin/main 709e2b319f. Every line the issue cites at 999cb91c1b still 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.
    • On the first test-only commit (hook equal to main) it gave PASS=127 FAIL=15. Every failure was a quiet: attach ... case or deny: attach adjacent alt home path.
    • Each later round's new deny cases were red before their code change:
      • 16 failures for the vanishing-word cases;
      • 8 for the PowerShell double-quote cases;
      • 12 for the 6 deny: PowerShell attach judged whole: ... cases, run against the previous head's code.
    • The scan-root quiet cases (project root under /tmp) were red on main, which proves CLAUDE_PROJECT_DIR reaches the hook.
  • Mutation checks on Bash code:
    • Disabling the dash-flag rule fails 4 deny cases.
    • Making every operand literal fails the brace and $IFS deny 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).
    • Dropping the backtick from the literal check fails the backtick-substitution case.
  • plugins/guardrails/hooks/block-fix-request-post.test.sh: PASS=316 FAIL=0 on the branch and on a git archive extract of main in the same checkout. The hook and its test are unchanged.
  • shellcheck -x is clean on the three shell files. typos is clean on all changed files.
  • scripts/check-changelog-fragments.sh --check and --check-required origin/main pass.

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):

Arm main exit main median main max branch exit branch median main launches branch launches
a1 direct 2 45 46 0 26 21 (15 grep, 4 head, 1 jq, 1 tr) 10 (9 grep, 1 jq)
c0 direct 0 19 19 0 19 5 5
a1 dispatched 2 47 48 0 30 - -
c0 dispatched 0 21 22 0 21 - -
r1 direct, scan root 2 49 50 0 24 25 (1 git, 15 grep, 7 head, 1 jq, 1 tr) 8 (1 git, 6 grep, 1 jq)

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:

  • Counts: met (a1 10 ≤ 21, r1 8 ≤ 24, c0 5 = 5).
  • Wall time on the same host: met. Every branch median is at most main's slowest run of the same arm.
  • Missing tool: not applicable, since hyperfine 1.21.0 was present.
  • Windows-only symptoms: no timing claim is made. The PowerShell-tool deny cases pin the PowerShell behavior.

Done-when status for the final code:

  • AC1, AC2, AC3, AC4: met (Bash).
  • AC5: met (Bash spaced and adjacent alt text, project root in the alt text).
  • AC6: met.
  • AC7: met.
  • AC8: partly met.
    • --body "$X" --attach <home>/x.png exits 0 under Bash.
    • The PowerShell operand with a home path after # exits 2.
    • The PowerShell single-quoted <win home>\...\x.png operand exits 2, not 0; it is pinned as a deny case.
  • AC9: met (316/316 on both).
  • AC10: met. Each round's new cases were red first, and the head exits 0. The PowerShell quiet cases the issue named were turned into deny cases.
  • AC11: met (library header, guard header, README row 99).
  • AC12: met. bash scripts/check-changelog-fragments.sh with no argument exits 2 with a usage line, so it was run as --check and --check-required origin/main; both pass.
  • AC13: met (c0 total=5; a1 10 ≤ 21; r1 8 ≤ 24).
  • AC14, AC15: met.
  • AC16: partly met. The Baseline rerun and launch counts are done. The /code-metrics complexity, /code-metrics:audit-duplication and /simplify passes were not run.
  • AC17: not met. /review:quality-gate code 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 --attach operand is still judged whole, as on main. Three review rounds each found a PowerShell shape that would post a home path. The classes were:

    • a word that vanishes or is dropped;
    • quote characters that PowerShell's native argument passing does not escape;
    • the stop-parsing token with an environment-variable expansion;
    • a trailing backslash.

    The guard's tokenizer cannot model PowerShell's passing reliably, so the exemption was withdrawn there.

  • AC16's metrics, duplication and /simplify passes, and AC17's quality gate, were not run.

Related

🤖 Generated with Claude Code

session: GitHub Support

kyle-sexton and others added 9 commits November 13, 2026 18:39
…-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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T00:24:54.727215Z 8645936 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

Lane run report

Field Value
Activity pr-refine/fix-docs
Model rung 0
Leg handoff
Run job success
Activity step success
Commits pushed none (read lane)
Run 43533883890

Failed GitHub API calls

Method Path Status
GET /repos/{repo}/git/ref/tags/* 404

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 8645936854f305f9d065c3c90e37a6178f76feae: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

critical-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, plugins/guardrails/hooks/block-github-post-content.sh, and the segment loop in plugins/guardrails/lib/github-post/github-post-body.sh.

What changes. Under the Bash tool, block-github-post-content now judges a literal gh pr|issue --attach operand only by what gh posts from it: the text after the first # and the base name, split on /. That way the operand's source directory is no longer refused as a posted machine path.

What I checked:

  • Secret scan is still whole. attach texts go through ghpost::_add attach into GHPOST_BODY. The secret loop at block-github-post-content.sh#L153 scans every GHPOST_BODY entry before the path pass, and only the path pass (#L195-L205) shortens the text. A token anywhere in the operand still blocks, and the new tests token in attach alt text and token in the attached file's name cover it. block-fix-request-post reads the same GHPOST_BODY, so it still sees the whole operand.

  • No smuggling through the capture. A word is captured as an operand only when:

    • the word before --attach is not a dash flag without = (github-post-body.sh#L455);
    • the operand holds no $, backtick, { or glob character (#L211-L213);
    • for the joined --attach= form, the word before it is also literal (#L459).

    If a vanished word leaves a flag right before the spaced form, the operand becomes a positional argument. gh then rejects it or reads it as the selector, so it is not posted. The skip path that could leave attach set applies only to curl and gh api, never to gh pr|issue. attach is a local, so it does not carry into the next segment.

  • PowerShell is unchanged. Every operand there is still judged whole (#L448).

  • Severity bar. This is a local deterrent hook for the owner's own session. The path pass it narrows guards against posting a home directory or the project root. That is neither a token or secret leak, a compromise, nor a charge, so no severity-bar path exists. No trust control, merge hold, kill switch, token scope or plugin manifest is touched (plugin.json is unchanged).

  • Instruction-surface lens. The narrowed block still judges every byte gh posts from the operand. Nothing that rule protected now reaches GitHub unchecked, so I found nothing under this lens.

The README row and the .changes fragment are documentation only. The test file adds cases only.

Spend. None beyond this review run.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 8645936854f305f9d065c3c90e37a6178f76feae: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk of all 5 changed files. To check the change in context, I also read the unchanged code around it: ghpost::segment, ghpost::bodies and ghpost::collect in plugins/guardrails/lib/github-post/github-post-body.sh, the secret and path passes in plugins/guardrails/hooks/block-github-post-content.sh, and the consumer of GHPOST_BODY in plugins/guardrails/hooks/block-fix-request-post.sh.

What I checked

  • Where the operands go.
    • A captured --attach operand stays in GHPOST_BODY with kind attach.
    • The secret pass in block-github-post-content.sh iterates over every GHPOST_BODY entry, so it still judges the whole operand.
    • block-fix-request-post.sh reads every entry regardless of kind (L284-288), so adding the new kind does not narrow it.
    • Only the path pass narrows the operand: it judges the text after the first # plus the base name, split on /.
  • The rule about the word before --attach. I checked it against how gh's flag parser (pflag) treats short and long flags.
    • A long flag written with = is always complete.
    • A short flag followed by = (-b=, -b=x) takes its value from the same word.
    • In a short-flag cluster, a = after position 1 either becomes a value or causes an "unknown shorthand" error.
    • So a dash word that contains = can never take the next word as its value, and the exemption for it holds.
    • The - exemption is safe because - is never a flag.
  • The joined form after a word that is not literal. The joined --attach=<v> form is captured only when the word right before it is literal. In the vanishing-word and splitting cases I tried, any word that ends up before the joined word at run time is either that literal word or an argument already taken as a value. I could not build a case where a flag lands right before the joined word.
  • The spaced form.
    • If the shell drops or splits the word before --attach X, the flag before takes --attach as its value. X then becomes a positional argument that gh rejects or reads as the PR/issue selector, so nothing gets posted.
    • A non-literal word right after --attach clears the pending state, and that word falls through to GHPOST_TEXTS, so it is judged whole.
  • State does not leak between segments. attach, prev and before are locals of ghpost::segment, and re-entered parses (bash -c, eval, wrappers) recurse through it.
  • Alt text and base name. The text after the first # contains whatever gh would post whether it splits on the first or the last #. A base name split on / cannot hold a Unix home path, and a Windows path with backslashes stays whole.
  • PowerShell. Nothing is captured under the PowerShell tool, so every operand is judged whole as before. The new PowerShell deny cases pin that.
  • Changelog fragment. bump: patch with ### Fixed matches a fix to a false positive. No plugin.json or marketplace.json changed, so the manifest checks do not apply.

PR context

  • The description says Refs: #15979 and has no closing-issue section, so the closing-issue criteria do not apply.
  • The author lists PASS=186 FAIL=0, mutation checks, a clean shellcheck run and timing tables. I did not run these, so they are unverified.
  • The author says AC16 (metrics, duplication and /simplify passes) and AC17 (/review:quality-gate) were not run, and that the PowerShell half of AC8 is not delivered. I note these as stated, not as findings.

Spend: none. The change adds no CI, model or schedule use.

Verifier dropped 0 of 0 candidates.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit e44f4e7 Nov 14, 2026
55 checks passed
@kyle-sexton
kyle-sexton deleted the fix/guardrails-attach-paths-15979 branch November 14, 2026 00:47
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant