Repository navigation
fix(hooks): Gemini hook fails closed on malformed JSON payload (#111 G2) - #114
Merged
Merged
Conversation
The Gemini hook owns the allow/deny verdict. run_gemini parsed the
agent payload with `serde_json::from_str(...).context(...)?`, so a
malformed payload bubbled an Err through run(), exited non-zero with no
decision JSON, and the agent harness treats that as ALLOW — a silent
fail-open.
Mirror the hardening already applied to run_claude: on a JSON parse
failure or an oversized/unreadable stdin, emit a Gemini-format deny
decision to stdout and return Ok(()) — fail closed. Split the decision
logic into run_gemini_decision so the parse-failure path is testable.
The Cursor hook keeps its {}-on-parse-failure fail-open, now documented
as deliberate: Cursor's own permission engine is the backstop there.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closed
8 tasks done
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.
Summary
Fixes the G2 IMPORTANT from the independent Claude review (#111). Codex-reviewed: mergeable, no findings.
run_geminiparsed the agent payload withserde_json::from_str(&input).context(...)?— a malformed payload bubbledErr, exited non-zero with no decision JSON, and the harness treats that as allow (silent fail-open). The Gemini hook owns the allow/deny verdict, so this was a real exposure. The Claude path was hardened to fail closed in #100; Gemini was missed.Fix
run_gemininow emits a Geminidenyand returnsOk(())instead of?-bailing.read_stdin_limited()errors (oversized/unreadable stdin) also fail closed with a deny.emit_gemini_deny(reason)—{"decision":"deny","reason":...}viajson!(serde-escaped, no raw interpolation).{}-on-parse-failure as a deliberate fail-open (Cursor's own permission engine is the backstop).Test plan
cargo test --workspace— 2343 lib pass, 0 fail; newtest_gemini_malformed_json_fails_closedcargo build --releasecleanPart of the #111 audit.
🤖 Generated with Claude Code