Skip to content

fix(hooks): Gemini hook fails closed on malformed JSON payload (#111 G2) - #114

Merged
thehoff merged 1 commit into
developfrom
fix/g2-audit-111
May 20, 2026
Merged

thehoff merged 1 commit into
developfrom
fix/g2-audit-111

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the G2 IMPORTANT from the independent Claude review (#111). Codex-reviewed: mergeable, no findings.

run_gemini parsed the agent payload with serde_json::from_str(&input).context(...)? — a malformed payload bubbled Err, 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

  • On JSON parse failure, run_gemini now emits a Gemini deny and returns Ok(()) instead of ?-bailing.
  • read_stdin_limited() errors (oversized/unreadable stdin) also fail closed with a deny.
  • New emit_gemini_deny(reason) — {"decision":"deny","reason":...} via json! (serde-escaped, no raw interpolation).
  • Cursor hook left as-is with a comment marking its {}-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; new test_gemini_malformed_json_fails_closed
  • cargo build --release clean
  • Codex review — mergeable

Part of the #111 audit.

🤖 Generated with Claude Code

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]>
@thehoff
thehoff merged commit 53e9cec into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the fix/g2-audit-111 branch May 20, 2026 10:49
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.

1 participant