fix(security): reject non-UTF-8 responses and fix injection tracking - #199
Merged
Merged
Conversation
Closes #154, #155, #156. INJECT-005: Decode response bytes with errors="strict" before injection scanning. Non-UTF-8 payloads are rejected with injection_pattern= "non-utf8-response" to prevent bypass via byte sequences that errors="replace" would silently corrupt before pattern matching. POLICY-006 / INJECT-004: AGT MCPResponseScanner denial no longer overwritten by a subsequent regex-stage allow. injection_detected flag now reflects both scanners so session.update_from_inspection() always records InjectionEvent when either scanner fires. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
injection_detectednow reflects both scanners; session always recordsInjectionEventwhen either fireserrors="replace"would corrupt byte sequences an attacker could exploit to bypass pattern matchingTest plan
test_pipeline_denies_non_utf8_response— non-UTF-8 payload → deny withnon-utf8-responsepatterntest_pipeline_non_utf8_calls_session_update_with_injection_detected—injection_detected=Trueon non-UTF-8 pathtest_agt_mcp_scanner_deny_sets_injection_detected_on_session— AGT MCP scanner deny setsinjection_detected=Trueon sessiontest_agt_mcp_scanner_deny_is_not_overwritten_by_regex_allow— final decision is "deny" even when regex stage returns "allow"🤖 Generated with Claude Code