fix: hash full query in gate audit events for cross-path hash parity#79
Merged
Merged
Conversation
The /query handler passed req.query[:50] to audit_log for the prompt_injection_blocked and graph_error events. audit_log() replaces the 'query' field with hash_query(query) before persisting, so truncating to 50 chars produced a query_hash of only the first 50 characters. That hash does not match the canonical full-query hash written by the graph audit node (graph.py) or the MCP path (mcp_hybrid_server.py) for the same query, breaking cross-path correlation of audit events for queries longer than 50 chars. Pass the full query in both calls. No raw query text is persisted either way (the field is hashed), so this is purely a correctness fix that restores the same hash-parity guarantee already asserted for the MCP path in tests/test_mcp_server.py. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ECr44xGUy4SDEJRSmDPNZb
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.
Problem
In
gate.py, the/queryhandler logged two audit events with a truncated query:But
audit_log()(utils/logger.py) does not store the query verbatim — it replaces thequeryfield with its SHA-256 hash:So
req.query[:50]produces aquery_hashof only the first 50 characters. That hash does not match the canonical full-query hash written for the same query by:graph.pypasses the fullquerytoaudit_log, andmcp_hybrid_server.pypasses the full query (this was a deliberate fix;tests/test_mcp_server.py:292assertsevent["query_hash"] == hash_query(long_query)).Result: for any query longer than 50 chars, an injection-blocked or graph-error event can never be correlated by hash with the same query seen on the MCP/graph paths — defeating the purpose of the shared
query_hash.Change
Pass the full
req.queryin bothaudit_logcalls (truncation removed). Added a short comment noting the field is hashed downstream.Benefit
query_hashparity (HTTP gate ↔ graph audit ↔ MCP) for queries of any length — the same guarantee already test-asserted for MCP.🤖 Generated with Claude Code
Generated by Claude Code