Repository navigation
fix(guardrails): scan Bash-posted GitHub bodies for secrets and machine paths - #12093
Conversation
…library block-fix-request-post's parse of what a gh or curl command posts moves to lib/github-post/github-post-body.sh unchanged, so a second guard can read the same bodies. The fix-request contract test passes unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne paths block-github-post-content joins the Bash and PowerShell row. It reads what a gh or curl command posts to GitHub through the shared github-post library and runs the secret-pattern-detection and hardcoded-path-check pattern sets over it. A secret block names the pattern class, never the value. The path scan skips the whole command and every file path it names, so a wrapper script's path or a --body-file operand is not judged. The library now reads the command a script wrapper runs after `--` (`bash gate.sh run KEY -- gh ...`, split on bare `+++`), which also closes that route for block-fix-request-post. hpc_resolve_scan_root moves into the path pattern library as hpp::resolve_scan_root so both guards share it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cter budget Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rl flags From the ready-step review: a here-doc is judged only when the whole command counts toward the post, so one that feeds another command stays quiet; a GitHub-hosted runner's home in a quoted CI log is not a machine path; and curl short flags written together (`-sSd`) and `--expand-data` are read as data flags. The guard header lists the remaining gaps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47562e9df7
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
claude-security-review reviewed Security review (incremental, abdb7ed → 2cb62f3): no findingsI read every hunk of What changed. The path scan no longer removes a Checked, no finding
Prior findings: none are open. The one earlier inline finding ( critical-findings: 0 |
|
claude-review reviewed Code review: PR #12093, incremental since
|
A bug report that names `<drive>:\repos\<repo>` names no user, and earlier PR bodies cite one routinely, so block-github-post-content no longer blocks on the Windows repo-path blocks. User homes and this session's own checkout root still block. A stay-quiet case pins it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane-Activity: pr-unblock/resolve-conflicts
Resolves the guardrails README guard table: #12014's fix-request row, then the block-github-post-content row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgcHpe4YpFuL5b24Ft2
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgcHpe4YpFuL5b24Ft2
From the review threads on #12093: a curl `-H 'Authorization: ...'` value is transport, not posted content, so it no longer counts as a body word. The path scan now drops only a word that names one of the posting command's own body files (`<path>`, `--flag=<path>`, `@<path>`, `k=@<path>`), where it cut every `cat` or body-file name out of the body and title text, which let a home path through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd shape From the second round of review threads on #12093: the header skip applies only to curl and `gh api` and only to a separate `-H <value>` or `--header=<value>`, so a body that starts with `-H` is read again. The path scan drops each operand shape the library records a body file from (joined `-F<path>` and `-d@<path>`, curl `k=@<path>;type=`, `k=<<path>`, `name@<path>`) and cuts a quoted `$(cat <path>)` out of a body word, so a clean home-dir body file no longer blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… word From a review thread on #12093: cutting `$(cat <path>)` out of a longer body word let a single-quoted, posted-as-written home path through. The path scan now drops the word only when it is exactly `$(cat <path>)`, `$(<path>)` or a backtick `cat`, and reads any longer word whole. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ine paths under Bash (#16066) 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](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/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 - #12093 introduced the Bash-posted body scan this narrows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) session: GitHub Support --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
No related issue: security gap found by a PR Lane audit
Summary
secret-pattern-detection.shandhardcoded-path-check.shran only on the Write/Edit/NotebookEdit row and the MCPpush_files/create_or_update_filerow. The Bash|PowerShell row had neither. So agh pr|issue comment|review|create|edit --body ..., a writinggh api, or a curl POST to the GitHub API, run through Bash, posted its body publicly with no secret or machine-path scan. That was true for a bare command and for one inside a wrapper.Fix
block-fix-request-post.sh's parse of what a gh/curl command posts moves intoplugins/guardrails/lib/github-post/github-post-body.sh. That covers body words,--body-file/-F/stdin, here-strings,gh apifields and--input, curl data flags, andbash -c/evaloperands. The first commit is the move alone, and the fix-request contract test passed unchanged on it.block-github-post-content.shon the Bash|PowerShell row. It runs the existing pattern sets over the extracted bodies:lib/secret-detection/secret-patterns.shandlib/path-detection/hardcoded-path-patterns.sh, both sourced, not copied.GitHub PAT), never the value.hpc_resolve_scan_rootmoves into the path library ashpp::resolve_scan_rootso both use one copy.--body-fileoperand is not judged. A GitHub-hosted runner's home in a quoted CI log is not judged either.block_github_post_content_enabled.secret_pattern_detection_enabledandhardcoded_path_check_enabledalso turn off their half.--in a shell-script wrapper (bash gate.sh run|batch|call KEY [quiet] -- CMD [+++ CMD],./x.sh ... -- CMD) as its own segment, split on bare+++. It also reads curl short flags written together (-sSd) and--expand-data. Both also widenblock-fix-request-post.hook::bash_parse_segments. Basis:plugins/guardrails/hooks/hook-utils.shis a generated copy oflib/hook-utils.sh, one of 21 copies listed inscripts/shared-copies.txt(line 441). A change there regenerates 20 plugins' copies, andsync-shared-copies.sh --check-bumpthen needs a fragment in each of them. That is too wide for one PR.hook-utils.sh.Verification
Each suite was run alone in the worktree:
block-github-post-content.test.sh: PASS=60 FAIL=0. Each case runs alone and underrun-guards.shbehind block-fix-request-post.gh pr comment --bodywith a runtime-built fakeghp_token; the same post wrapped in gate.shrun; a gate.shbatchwith the token in the second command;./wrap.sh -- ...;--body-file; a heredoc to--body-file -; a$(cat <<EOF)body;gh api -f; curl-sSdand-d;bash -c; PowerShell. Three home-path deny cases.--body-fileoperand; a home path in a here-doc that feeds another command; a hosted-runner path in a quoted CI log; a token in a grep, in an env prefix, in agh apiGET, and in a curl to another host.-sSddeny case were reproduced against 3d41a32 by the review agent: rc=2, rc=2, rc=0.block-fix-request-post.test.sh: PASS=304 FAIL=0, all existing cases plus two new wrapped deny cases (run --andbatch ... +++).hardcoded-path-check.test.sh: PASS=162.run-guards.test.sh: PASS=714.coverage-manifest.test.sh: 32 checks passed.onfailure-rows.test.sh: PASS=3.scripts/check-affected.sh(13 passed),check-killswitch-hoist,check-hook-slow-shapes,check-hooks-description,check-hook-userconfig-argv,check-test-tmp-cleanup,check-pipefail-grep-q. shellcheck reports nothing.gh pr merge --body,gh release --notesandgh gist) and the LOW findings are listed as known gaps in the guard header.Related
.changes/guardrails/fix-guardrails-bash-body-secret-scan-5b3e91c7.md(minor).🤖 Generated with Claude Code