Python: Feature request: Memory poisoning defense (OWASP ASI06) integration
Summary
OWASP recently published the Top 10 for Agentic Applications, which includes ASI06: Memory Poisoning — a threat category specific to AI agents that persist memory across sessions.
As Semantic Kernel adds more persistent memory and agent loop capabilities, it would be valuable to have a built-in or recommended defense layer for this attack surface.
The threat
When an agent stores information in memory (conversation history, retrieved facts, tool outputs, scratchpads), a malicious actor can craft inputs that get stored as "trusted" memories. Those poisoned memories then influence the agent's future behavior — causing it to leak data, take unauthorized actions, or be persistently manipulated across sessions.
This is distinct from prompt injection (which targets user input at the front of the loop) — memory poisoning targets the memory store itself.
Proposed integration
The OWASP reference implementation for ASI06 is agent-memory-guard (MIT/Apache-2.0 licensed, pure Python, zero external dependencies):
pip install agent-memory-guard
It provides:
- Runtime memory validation (prompt injection, secret leakage, protected-key tampering)
-
- Cryptographic integrity verification (SHA-256 baselines)
-
-
- Declarative YAML policy engine
-
-
-
-
- Point-in-time snapshots and rollback
-
-
-
-
-
-
- Drop-in middleware for common memory backends Suggested integration points for Semantic Kernel:
-
-
-
- A
MemoryGuard-wrappedISemanticTextMemoryadapter -
- Optional middleware hook in the kernel's memory pipeline
-
- Documentation guidance on memory security best practices per OWASP ASI06
References
- OWASP Top 10 for Agentic Applications: https://genai.owasp.org/
-
- agent-memory-guard (OWASP reference impl): https://github.com/OWASP/www-project-agent-memory-guard
-
One practical way to make this easier to evaluate is to turn the report into a small contract test around the runtime boundary, not only the user-facing symptom.
For Python memory poisoning defense integration, I would check three things: first, the failing input is preserved as a minimal fixture; second, the SDK emits the same observable event/result shape before and after the fix except for the intended change; third, the trace or serialized session contains enough metadata to explain what happened after a resume or retry.
The part that matters for agent systems is durability: if a tool call, memory write, handoff, or structured-output step fails, downstream code should not have to infer state from natural-language output. A focused regression test around that boundary would make the issue much easier to close with confidence.
Memory poisoning is a real operational risk — we ran into a variant of this where an agent's recalled memories contained adversarial instructions that leaked into subsequent sessions. The scan-before-write pattern OWASP describes is necessary but not sufficient on its own. What we found equally important is session-scoped memory isolation: each agent session gets its own namespace, and cross-session recall goes through an importance-scored retrieval layer where low-confidence or anomalous memories get demoted automatically via decay weighting. This means even if a poisoned memory slips past the write-time scan, it loses influence over time unless it keeps getting accessed organically. The namespace isolation model is baked into our memory server — you can see how per-agent sessions work in the JS SDK at github.com/Dakera-AI/dakera-js where session_start / session_end create the boundary.
agree on the scan-before-write being necessary-but-not-sufficient. the session isolation + decay-weighting pattern handles cross-session leakage well, but there are two failure modes inside that envelope worth naming explicitly.
first, intra-session poisoning. session isolation doesn't help if the adversary controls multiple turns within a single session, which is the default for any agent that ingests user-pasted content or scrapes web context. the poison gets persisted with the same trust score as the legitimate context because they share the session namespace. a within-session write-side audit trail, separate from the cross-session boundary, catches this.
second, importance-score adversarial pressure. if the retrieval layer demotes low-confidence memories via decay, an adversary just learns to inject signals that boost importance (self-referential urgency markers, fake corroboration with prior turns, stylistic patterns the scorer rewards). the scorer itself becomes the new attack surface.
what's helped in practice: writing memory with provenance tags (who told the agent first vs who confirmed vs who contradicted), and gating high-importance writes through a separate confidence-interval check instead of trusting the recall-side score. trust hierarchy at write time, not just retrieval.
doesn't replace OWASP ASI06's scan layer, layers under it for the cases where a poisoned input passes initial inspection.