fix(sanitizer): suppress false positives for memory retrieval (Issue #2025)#2053
Merged
fix(sanitizer): suppress false positives for memory retrieval (Issue #2025)#2053
Conversation
…2025) Introduces `MemorySourceHint` enum to distinguish memory retrieval sub-sources and modulate injection detection sensitivity in `ContentSanitizer::sanitize`. - ConversationHistory hint (recall, corrections): detection skipped — user's own prior messages legitimately contain "system prompt", "show instructions", etc. - LlmSummary hint (summaries, cross_session): detection skipped — generated by the agent's own model from already-sanitized content, low poisoning risk. - ExternalContent hint (doc_rag, graph_facts): full detection retained — may contain adversarial content from web scrapes or MCP responses stored in the corpus. Defense-in-depth invariant: truncation, control-char stripping, delimiter escaping, and spotlighting remain active for ALL memory sources regardless of hint. Merge conditions addressed: 1. `tracing::debug!` logged when injection detection is skipped (audit trail). 2. Quarantine path verified: MemoryRetrieval is NOT in default quarantine sources (web_scrape, a2a_message), confirmed by test `quarantine_default_sources_exclude_memory_retrieval`. 3. Tests use actual false-positive-triggering strings ("system prompt", "show your instructions") and include a non-memory regression guard (WebScrape still detects). Test count: 6041 → 6054 (+13 new unit tests in zeph-sanitizer).
c31fa32 to
e7c3bc5
Compare
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 false injection warnings when retrieving legitimate user queries from memory. The
ContentSanitizerwas incorrectly flagging prior conversation turns as injection attempts because it couldn't distinguish between:Root Cause
assembly.rs::sanitize_memory_message()applied uniform injection detection to all 6 memory retrieval paths usingExternalUntrustedsensitivity. This caused patterns likesystem_promptandreveal_instructionsto fire on legitimate user queries.Solution
Introduced
MemorySourceHintenum to distinguish memory sources:ConversationHistoryLlmSummaryExternalContentAll other pipeline steps (truncation, escaping, spotlighting) remain active for all sources — defense-in-depth is preserved.
Changes
crates/zeph-sanitizer/src/lib.rs: AddedMemorySourceHintenum, extendedContentSource, modulateddetect_injections()crates/zeph-core/src/agent/context/assembly.rs: Threaded hints through all 6 memory retrieval call sitesMerge Conditions (All Addressed)
✓ Audit trail:
tracing::debug!logs when injection detection is skipped✓ Quarantine interaction: Test 9 verifies
memory_retrievalis not in default quarantine sources✓ False-positive strings: Tests 1 & 3 use exact Issue #2025 triggering strings ("system prompt", "show your instructions")
Testing
Acceptance Criteria
cargo clippy --all-targets --all-features --workspace -- -D warningspassesCloses #2025