Skip to content

fix(guardrails): say when check-bash-file-changes could not run - #6988

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/guardrails-bash-file-changes-failure-notice
Oct 11, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/guardrails-bash-file-changes-failure-notice

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #6905

Summary

check-bash-file-changes.mjs ended with main().catch(() => {}), so an unexpected exception exited 0 with nothing on stderr or stdout. That contradicted the guardrails README's "Every hook says so when it could not run". The shell hooks get that notice from hooks/abort-boundary.sh; this Node hook had no equivalent.

Fix

  • The top-level catch now writes the same one-line notice the abort boundary gives a fail-open hook, guardrails check-bash-file-changes: guard did not run (internal error, rc=1); this call was not checked. Details: claude --debug., to stderr (followed by the error stack for the debug log) and as {"systemMessage": ...} on stdout. It exits 0, the hook's declared fail-open posture. rc=1 is the status an uncaught error would have ended Node with.
  • Normal behavior and the existing "not examined" skip notes are unchanged.
  • Kept local: no other guardrails .mjs guard has the gap. exec-bash.mjs is a generated shared launcher with no swallowing catch.
  • README: the abort-boundary bullet now says the Node guard gives the same notice from its own catch.
  • Changelog fragment .changes/guardrails/... (patch).

Verification

  • New cases in hooks/check-bash-file-changes.test.sh:
    • D1: CLAUDE_PLUGIN_DATA names a file, so the snapshot's mkdirSync throws. Asserts exit 0, the exact systemMessage, a single stdout document, and the notice as stderr's first line.
    • D2: the check reads a snapshot holding null, so main() throws in check mode. Same assertions.
    • 5h (stay quiet): a normal snapshot and check with a benign change leave stdout and stderr empty and exit 0.
  • Before the fix, D1 and D2 failed (5 assertions) and 5h passed. After the fix: PASS=60 FAIL=0.
  • Full guardrails suite: all 24 hooks/*.test.sh exit 0, and node --test hooks/exec-bash.resolver.test.mjs passes.
  • scripts/check-changelog-fragments.sh --check passes. shellcheck is clean on the test file.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 11, 2026 00:16
An unexpected error in check-bash-file-changes.mjs was swallowed by
main().catch(() => {}), so the hook exited 0 with no output. It now gives
the fail-open notice the shell hooks' abort boundary gives: "guard did not
run (internal error, rc=1); this call was not checked" on stderr and as a
systemMessage, and still exits 0.

Closes #6905

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hook change, its tests and the README line that the previous commit
left unstaged.

Refs: #6905

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 11, 2026 04:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T04:22:18.340931Z e72d934 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.

@claude

claude Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 4s —— View job


Security review complete ✅

  • Gather context (diff, changed files)
  • Review changed files for security issues
  • Check for instruction-surface deletions
  • Report findings

Scope: plugins/guardrails/hooks/check-bash-file-changes.mjs, plugins/guardrails/hooks/check-bash-file-changes.test.sh, plugins/guardrails/README.md, .changes/guardrails/fix-guardrails-bash-file-changes-failure-notice-5caf42e1.md (diff: origin/main...HEAD, head e72d934).

No security issues found.

Analysis:

  • The only behavioral change is in check-bash-file-changes.mjs lines 523–532: the top-level main().catch(...) now writes a fixed notice string to stderr/stdout instead of swallowing the error silently.
    • Fail-open posture is unchanged. The hook already exited 0 on any internal error before this PR (main().catch(() => {})); this diff only adds a notice on the same path. It does not create a new bypass of the guard — an attacker who could already force an exception to skip checking (e.g. by corrupting a snapshot file under CLAUDE_PLUGIN_DATA, which already requires local write access to trusted plugin data) gets no new capability.
    • No injection surface. The only value written to stdout is the constant DID_NOT_RUN string, JSON-encoded — no attacker-controlled data reaches stdout, so this can't desync the hook's JSON-based protocol with Claude Code.
    • stderr content. error?.stack ?? error is written raw to stderr (debug log only). Traced the reachable throw sites (mkdirSync/writeFileSync in snapshot(), and the null-snapshot property access in check()): none of them interpolate attacker-controlled repository file content into the thrown error's message — the messages carry only internal paths (under CLAUDE_PLUGIN_DATA, not repo-relative) or generic JS error text (e.g. "Cannot read properties of null"). All call sites that do handle repo-derived filenames/content (stamp, readContent, git, gitStatus, headLog, fileSize) already have local try/catch that return safe fallbacks instead of throwing, so this path doesn't carry repo-controlled strings into the debug log.
  • README.md only adds a clarifying sentence; it doesn't remove or weaken any guardrail, so the instruction-surface-deletion lens doesn't apply.
  • check-bash-file-changes.test.sh and the changelog fragment are test/doc-only, no security surface.

No GitHub Actions files are touched by this PR, so no zizmor-lane deferral applies.

@claude

claude Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 45s —— View job


Review: check-bash-file-changes failure notice (#6988)

  • Read trigger comment and PR description
  • Pulled the diff (git diff origin/main...HEAD) for the 4 changed files
  • Reviewed check-bash-file-changes.mjs catch-handler fix against abort-boundary.sh's fail-open notice path
  • Reviewed hooks.json invocation (direct node ... snapshot|check, no wrapper that would swallow the new stdout/stderr output)
  • Reviewed the new test cases (D1, D2, 5h) against check()/snapshot() control flow
  • Reviewed README and changelog-fragment wording
  • Attempted to run the test suite locally — blocked, see note below

No blocking or high-signal findings.

What I checked:

  • The DID_NOT_RUN string in check-bash-file-changes.mjs:524-525 is byte-for-byte identical to the message abort-boundary.sh's open-posture branch builds (guard::_abort_settle), so the Node guard's notice really does match the shell boundary's wording, not just in spirit.
  • Both snapshot() and check() write to stdout only once, at the very end of main() (line 506) — never before the point where an error could be thrown — so the new catch-handler write in check-bash-file-changes.mjs:527-531 can never produce two stdout documents for one invocation.
  • D2's fixture (null snapshot JSON) throws exactly where expected: before.failed is read on a null value at check-bash-file-changes.mjs:398, which JSON.parse('null') produces; the synchronous throw inside check() propagates out of the async main() and is caught by .catch() as intended.
  • check-bash-file-changes.mjs is invoked directly by hooks.json (node .../check-bash-file-changes.mjs snapshot|check), not through exec-bash.mjs's shared launcher, so there's no intermediate process that would intercept the new stderr/stdout output before it reaches Claude Code.
  • Author-claimed-and-unverified: I could not execute check-bash-file-changes.test.sh, the full hooks/*.test.sh suite, or check-changelog-fragments.sh myself — Bash execution was denied by this environment's permission settings. The PR description's PASS=60 FAIL=0 and "24 suites exit 0" results are the author's reported output, not something I independently confirmed. If this matters, grant Bash execution to this job's --allowedTools to let a future run verify it directly.
    · branch fix/guardrails-bash-file-changes-failure-notice

@github-actions

Copy link
Copy Markdown
Contributor

claude-review has reviewed this pull request through e72d934; a later push is reviewed from there.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review has reviewed this pull request through e72d934; a later push is reviewed from there.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 11, 2026
Merged via the queue into main with commit ac2760c Oct 11, 2026
45 of 46 checks passed
@kyle-sexton
kyle-sexton deleted the fix/guardrails-bash-file-changes-failure-notice branch October 11, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(guardrails): check-bash-file-changes swallows unexpected errors with no "guard did not run" notice

1 participant