Repository navigation
fix(hooks): aws-write-guard grades every segment, strips heredoc bodies, tells the true rule - #953
Merged
Merged
Conversation
…es, tells the true rule
athvin
marked this pull request as ready for review
November 9, 2026 01:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #926
What
Reworks
scripts/hooks/aws-write-guard.sh's matching and its messages, plus twelve new cases incodex-hooks-sync-test.sh(31 pass total). Heredoc BODIES are stripped before anything matches (heredoc content is data — the measuredgh pr createfalse positive dies at the root); the rest is split everywhere a command can start (pipes,&&/||,;, newlines) and each segment is graded by its own head;make cluster-objectsjoins the graded path. The destructive list still scans the whole stripped string, sobash -c-wrapped evasions stay denied.Why
The guard stated a rule that was wrong in both halves (cluster objects are not Terraform; agents may apply them with disclosure — and since #927 CI applies them on merge) and its first-word anchor was bypassed by the two commonest invocation shapes while firing on a heredoc body. A guard whose stated reason is wrong teaches the wrong rule every time it fires; a guard that blocks legitimate work gets disabled.
Proof
codex-hooks-sync-test.sh— 31 passed, 0 failed, including the new: pipe-wrapped apply denied (Codex semantics), heredoc-piped apply denied,make cluster-objectsdenied, second-line mutation denied, read-past-pipe passes, the heredoc-body string passes, and the Claude-side mapping still returnsaskfor the graded shapes whileER_GUARD_ASK_AS_DENY=1collapses them to deny.kimi-hooks-sync-test.sh14/0,scripts-home-check.shclean,bash -nclean. Documented residual, failing toward refusal: a multi-line QUOTED string (not heredoc) still splits on its newlines, so a body written that way with a deny-list string inside still trips.Risk & rollback
Risk: an over-match regression blocks legitimate commands — mitigated by the test table driving all three agents' payload shapes, and by the failure direction being refusal (annoying, not silent). Rollback:
git revert <merge-sha>; the hooks re-sync from the reverted file.Post-merge ledger
Closed by: agent · Codex session
01a1be1a-66a7-72f3-8e78-32c20c5e0da9onMac.lan· 2026-11-09T02:27:41.268226+00:00mainis green with this change on it — the merge SHA, and the run that proves it: e036803; rust run 42548210698, frontend 42548210747, infra 42548210714 and devcontainer 42548210710 succeeded.imagesbuilt, or correctly never ran because nothing that goes into an image changed: n/a — only hook scripts and their tests changed; no image inputs.deployconverged — proved by a line the running process emitted, not by the image digest and not by the workflow conclusion: n/a — this hook-only change triggers no deployment.deploy,drift,kind's nightly leg) is green, or knowingly red for a reason that is not this change: Latest observed deploy 42550495391, drift 42453080846 and kind 42455973323 all succeeded.Donethrough the automation rather than by hand, and the issue closed: Issue aws-write-guard: its stated rule and what it enforces disagree, in both directions #926 is CLOSED; its Product Roadmap card is Done.Specific to this change
scripts/codex-hooks-sync.shand the Kimi equivalent install by reference to this file, so a merge updates what sessions run; confirm one live session evaluates the new table (a graded command returns the new message): Primary checkout contains e036803; invoking scripts/hooks/aws-write-guard.sh with a synthetic kubectl apply payload returns the new CI-owned Terraform / cluster-objects disclosure message. No cluster mutation was executed.Context — plan, discoveries, measurements, files
Plan
;/newlines; grade per segment. 3.make cluster-objectsinto the graded path. 4. Rewrite both messages for the post-The deploy never applies infra/k8s cluster objects, so a new cluster is born without them #927 rule. 5. Tests for every measured shape, both mappings.Discoveries
kubectl get pods && kubectl apply -f xpassed silently, because the reads exemption matched the whole string unanchored. Per-segment grading closes it.bash -c '…'shows onlybashas a segment head; keeping the destructive list on the whole stripped string preserves today's coverage of that shape without re-introducing the heredoc false positive.Measurements
bash scripts/ci/codex-hooks-sync-test.sh→ 31 passed, 0 failed (12 new).Files
scripts/hooks/aws-write-guard.sh— the rework.scripts/ci/codex-hooks-sync-test.sh— the new cases.