Skip to content

refactor(guardrails): read the hook payload through one fail-closed helper - #15611

Merged
kyle-sexton merged 4 commits into
mainfrom
refactor/guardrails-shared-payload-read
Nov 12, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
refactor/guardrails-shared-payload-read

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #15610

Summary

Six guardrails hooks repeated the same three checks after their hook::jq_fields call: refuse and exit 2 on a payload jq rejects, exit 0 on any other failed read, refuse and exit 2 on a NUL byte in a read field. They now share guard::payload_verdict in plugins/guardrails/hooks/abort-boundary.sh. Part of restructuring pass #14622 (R5).

Built in a session, tests first, because it changes safety guards; the owner decided the route.

session: Simplify Planning

Fix

  • guard::payload_verdict <jq_fields status> returns 0 to read on, 2 after writing the refusal, 3 for a read the guard lets through silently. It never exits, as the other guard:: refusals do not.
  • Each hook keeps its own exit, in one form: guard::payload_verdict "$jq_rc" || exit $(($? == 3 ? 0 : 2)). Every status but 0 and 3 blocks, so a missing or misbehaving helper denies the call. abort-boundary.test.sh fails on any other call form.
  • Hooks changed: block-credential-read.sh, block-exported-msys-pathconv.sh, block-github-post-content.sh, block-no-verify.sh, block-root-delete-target.sh, block-windows-drive-tmp.sh. One comment in block-windows-drive-tmp.sh now says "any of these fields" (the read takes four).
  • Not changed: block-convention-violation.sh, block-dangerous-git.sh and block-noncanonical-commit.sh repeat only the NUL refusal and handle status 2 differently, so the helper would change their output.
  • Output, exit codes and the order of checks are unchanged for every payload.

Verification

  • Commit 1 adds the missing cases before any hook changes: an unparsable payload and a NUL byte per hook, and statuses 1 and 3 through one stubbed loop in abort-boundary.test.sh (no payload produces them). Each passed on the unchanged hooks, and 18 of 18 single-line breakages of those hooks failed a test.
  • After the refactor, 4 of 4 breakages failed a test: the helper's unparsable, NUL and other-failure paths, and a call site that ignores the verdict.
  • Suites: abort-boundary 299, credential-read 360, msys-pathconv 136, github-post-content 79, no-verify 470, windows-drive-tmp 846, root-delete-target-e 795, run-guards 734, require-jq-posture 56, root-delete-target main, b, c and d 1,568, 1,552, 1,457 and 1,069: all pass.
  • shellcheck clean; scripts/sync-shared-copies.sh --check (812 copies) and the cross-plugin drift check pass; changelog fragment and typos checks pass.
  • No changed file is a shared copy or a merge.diff-check.floor-paths row.

Related

Follow-ups

  • Pre-existing (advisory): plugins/guardrails/hooks/block-fix-request-post.sh:112-124 holds a seventh copy of this check in _bfr_settle_fields, which exits inside its helper.
  • Pre-existing (advisory): plugins/guardrails/hooks/block-convention-violation.sh:108 and plugins/guardrails/hooks/block-noncanonical-commit.sh:144 exit 0 on a payload jq rejects (status 2), and their comments name "rc 1". Refusing it would change what those guards allow, which is the owner's decision.
  • Pre-existing (advisory): the comment at plugins/guardrails/hooks/block-root-delete-target.test.sh:1001 said section 5 held a NUL-in-command test; none existed until this change added one to the -e suite.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH

kyle-sexton and others added 2 commits November 12, 2026 10:31
Six blocking guards refuse a payload jq cannot read and one carrying a NUL
byte, and let any other failed field read through. No suite reached the
unparsable branch: the "not JSON" cases stop in the stdin read first. These
cases send JSON whose fields jq cannot index, a NUL in a harmless command
where none was covered, and, through a stub of hook::jq_fields on a copy of
the plugin, statuses 1 and 3, which no payload produces. Each case fails when
its branch in the hook is broken.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH
…elper

Six blocking guards repeated the same checks after hook::jq_fields: refuse a
payload jq rejected, let any other failed read through, refuse a NUL byte in a
read field. guard::payload_verdict in abort-boundary.sh now decides and
returns, as that file's other shared refusals do; each guard keeps its own
exit in one form, `|| exit $(($? == 3 ? 0 : 2))`, which blocks on every status
but 0 and 3, so a missing or broken helper denies the call. abort-boundary.test.sh
unit-tests the helper and fails on any call not in that form.

The hook::jq_fields call stays in each guard, where run-guards.test.sh reads
its filters. The three guards that share only the NUL refusal keep their own
handling of an unparsable payload, which differs from these six, so they are
unchanged. No guard's output or exit code changes for any payload.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH
@kyle-sexton kyle-sexton added do-not-merge Hard merge gate: do not merge while applied. and removed do-not-merge Hard merge gate: do not merge while applied. labels Nov 12, 2026
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 12, 2026 16:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T16:39:04.379576Z d0b8d26 Draft marked ready
ℹ️ 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

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Security review: PR #15611 at fa972cfe (incremental since d8e4d9c9)

I found no security issues.

critical-findings: 0

This review was blocking only. The lane already reviewed an earlier head, so it reports only CRITICAL and IMPORTANT findings.

What I checked

One file was in scope: plugins/guardrails/hooks/abort-boundary.test.sh. I read its only hunk. The file doesn't match any trusted path.

  • What changed. The scan that finds callers of guard::payload_verdict used to pipe one grep into another: grep -F "$PV_EXIT" "$f" | grep -qv '^[[:space:]]*#'. It now feeds the second grep through process substitution: grep -qv '^[[:space:]]*#' < <(grep -F "$PV_EXIT" "$f"). This most likely avoids a false failure under pipefail: grep -q can exit early and send SIGPIPE to the grep -F writing into it. The outcome is the same either way. A hook is recorded as a caller only when at least one line that isn't a comment contains the exit-form call. When there's no match, grep -qv gets empty input and returns 1, so nothing is recorded.
  • Effect on the safety net. The check is no weaker. It still requires each of the six listed guard hooks to call the helper, and the verdict_unconsumed check is unchanged. No hook source changed in this push, so the earlier conclusion still holds: the six hooks refuse unparsable or NUL-carrying payloads as before.
  • No other security surface. The push doesn't touch any of the following:
    • hook runtime behaviour
    • a plugin manifest or userConfig key
    • a workflow, token or trust control
    • a merge hold
    • a standing instruction

Earlier review

The previous summary comment (no line anchor) reported 0 findings, so there is nothing to carry over.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on d0b8d26444b7c0711b9fdeb234ace4d6e54187ba; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Incremental code review: PR #15611 (d8e4d9c9 → fa972cfe)

I read the whole change in scope (1 of 1 files). The only file in scope is plugins/guardrails/hooks/abort-boundary.test.sh. This lane has already reviewed an earlier head (blocking only: yes), so this review reports blocking findings only. I found none.

What the push changes: one line, abort-boundary.test.sh#L273. The scan that finds the hooks calling the helper used a pipe: grep -F "$PV_EXIT" "$f" | grep -qv '^[[:space:]]*#'. It now uses process substitution: grep -qv '^[[:space:]]*#' < <(grep -F "$PV_EXIT" "$f").

  • The result no longer depends on SIGPIPE. The suite runs under set -uo pipefail. With the pipe, grep -q could stop reading at its first match while the first grep was still writing. The first grep would then exit with SIGPIPE (141), pipefail would make the whole line fail, and the hook would be left out of pv_callers even though it does call the helper. With process substitution, only the exit status of grep -qv decides the &&.
  • Failures still give the right answer. If the inner grep -F matches nothing, or cannot read the file, grep -qv gets empty input and exits 1. The file is then correctly left uncounted, so ignoring the inner status cannot add a false caller.
  • Nothing else changes. Comment lines are still excluded, so the doc-comment line in abort-boundary.sh still does not count. The six hooks are still checked by name at L279-L286, and the verdict_unconsumed check is untouched.
  • The settled thread stays settled. The resolved thread (discussion_r4553368814) was about the counter matching the doc comment. This change keeps that fix, and it raises no new problem on those lines.

I had no shell, so I did not run the suite. No manifest changed. I found no embedded instructions in the PR context, settled-threads or prior-findings files. No hold applies.

kyle-sexton and others added 2 commits November 12, 2026 12:14
The caller count matched the usage line in abort-boundary.sh's doc comment, so
it passed with every call removed. It now counts non-comment call lines only
and asserts each of the six guards by name, so one guard dropping out fails.

Refs: #15610

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH
The caller scan piped grep into `grep -q`, which the pipefail-grep-q
hygiene check refuses: the early exit can kill the producer. The scan
now reads the producer through process substitution; same result.

Refs: #15610

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit d50bedd Nov 12, 2026
55 checks passed
@kyle-sexton
kyle-sexton deleted the refactor/guardrails-shared-payload-read branch November 12, 2026 17:43
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 12, 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.

Read the guardrails hook payload through one fail-closed helper

1 participant