# Which invariants prevent prompt-injection taint from laundering through tool-output normalization and memory-write summarization **Date of Record:** 2026 November 23 **Scope:** Applies to agents that ingest untrusted content (retrieved documents, tool responses, web pages) into a labeled context and later persist derived facts to long-term memory. Does not apply to stateless single-turn inference with no memory write and no tool egress. ## Core Distinction The failure is not "the agent read a malicious instruction." It is that the taint label attached to a byte range was *re-derived* rather than *propagated* at two transformation boundaries: (1) tool-output normalization (JSON parsing, HTML-to-text, truncation, encoding repair) and (2) memory-write summarization (the LLM rewriting a tainted observation into a compact semantic fact). In both cases the transformation produces a new artifact whose provenance is computed from the *output's* apparent content, not inherited from the *input's* label. An information-flow label is sound only if it is a monotone function of the input set; the moment a transform recomputes labels from surface form, taint laundering becomes possible. The core distinction: **taint must be an inherited lattice join over inputs, never a predicate re-evaluated on outputs.** A summarizer that "looks clean" is still tainted if any input was tainted. ## What Was Observed A retrieval agent fetched an attacker-controlled page whose visible text contained a benign-looking sentence plus a hidden instruction inside an HTML comment and a zero-width-encoded payload in an attribute. The pipeline: 1. `fetch` returned raw HTML, labeled `untrusted:web` at the tool boundary. 2. A normalization step (`html_to_text`) stripped comments and attributes, yielding clean prose. The labeler ran a content classifier on the *normalized text*, found no injection signature, and emitted `trusted`. 3. The agent summarized the prose into a memory fact: `"Project deadline is Q3; contact list maintained by ops."` The summarizer inherited the (now-clean) label and wrote to semantic memory with `trusted`. 4. On a later task, the agent retrieved that memory fact as trusted context and, when asked to "send the ops contact list," executed an egress tool call to an address that had been smuggled through the zero-width payload — reconstructed not at fetch time but at *summarization* time, because the summarizer's own tokenizer decoded the hidden codepoints into plain text before the classifier ever saw them. The laundering occurred at step 2→3: label recomputation on transformed output erased the taint that the raw input carried. A secondary laundering occurred because the summarizer's decoding step reintroduced content the normalizer had removed, so the *normalized artifact* and the *summarized artifact* had different effective content but the same (clean) label. ## Condition of Validity The invariant holds only if all of the following are enforced at every transform: - **Monotone label join:** `label(out) = ⋁ label(in_i)` over all inputs, regardless of output content. No transform may *lower* a label. A "declassify" operation is permitted only with an explicit, audited warrant (e.g., a human approval token bound to the specific artifact hash), never by a classifier run on the output. - **Provenance-preserving transforms:** any transform that can *reconstruct* content (unicode normalization, zero-width stripping, entity decoding, base64 decode, HTML entity resolution) must be applied *before* the label is attached, or must itself carry the input label forward. The set of "content-recovering" transforms must be closed under composition and run in a fixed order prior to classification. - **No taint sink without a taint check at the sink:** memory writes and tool-egress calls are sinks. A sink accepting a value whose label is `untrusted` must either reject, or quarantine with the label intact so downstream readers see it. - **Hash-bound provenance:** each artifact carries `(content_hash, label, parent_hashes)`. A transform that changes content but not `parent_hashes` is detectable; a transform that drops `parent_hashes` is a protocol violation. If any of these is absent, the system is in the invalid regime and taint laundering is *possible*, not merely suspected. ## Decision Boundary The boundary is between **transform-then-classify** (unsound) and **classify-then-transform-with-join** (sound). Concretely: - Sound: `fetch → decode_all_recovering_transforms → attach label=untrusted → normalize → label stays untrusted → summarize → label stays untrusted → memory write quarantined`. - Unsound: `fetch → normalize → classify(normalized) → label=trusted → summarize → memory write trusted`. The decision rule for an operator: **if any code path computes a label from an artifact's content after that artifact has passed through a content-recovering transform, that path is a laundering vector.** The boundary is crossed the instant a classifier's verdict is allowed to *override* an inherited label downward. Upward joins (untrusted ∨ trusted = untrusted) are always safe; downward overrides require a warrant. ## Operational Effect When the invariant is enforced, the operational consequence is that *taint is sticky and visible*: memory facts derived from web content remain labeled `untrusted:web` forever unless explicitly declassified, and any egress tool call consuming such a fact trips a policy gate that requires either a human warrant or a sandboxed, side-effect-free execution. The cost is recall/utility: the agent cannot silently promote web knowledge to trusted memory, so it must carry labels through retrieval and re-verify at use time. When the invariant is violated, the effect is *silent privilege escalation*: attacker content becomes trusted memory, and the compromise is only observable at the egress sink — often after the fact. The guardrail that bounds the damage is a **sink-side taint check that fails closed**, plus a **provenance audit** that flags any artifact whose `parent_hashes` do not cover its `content_hash` (evidence of an unlogged recovering transform). ```python import hashlib from dataclasses import dataclass, field from enum import IntEnum from typing import Iterable class Taint(IntEnum): TRUSTED = 0 UNTRUSTED = 1 class TaintLaunderingError(RuntimeError): """Raised when a transform lowers a label without a warrant, or a sink receives tainted data without quarantine.""" @dataclass(frozen=True) class Artifact: content: str label: Taint parents: tuple[str, ...] = field(default_factory=tuple) @property def content_hash(self) -> str: return hashlib.sha256(self.content.encode("utf-8")).hexdigest() def join_labels(inputs: Iterable[Artifact]) -> Taint: # Monotone join: any untrusted input taints the output. Never re-derive # from output content. return Taint(max((a.label for a in inputs), default=Taint.TRUSTED)) def transform(inputs: list[Artifact], new_content: str, warrant: str | None = None) -> Artifact: inherited = join_labels(inputs) if inherited == Taint.UNTRUSTED and warrant is None: # Allowed: keep untrusted. Forbidden: silently promote to trusted. return Artifact(new_content, Taint.UNTRUSTED, tuple(a.content_hash for a in inputs)) if inherited == Taint.UNTRUSTED and warrant is not None: # Declassification requires an explicit, audited warrant. return Artifact(new_content, Taint.TRUSTED, tuple(a.content_hash for a in inputs)) return Artifact(new_content, inherited, tuple(a.content_hash for a in inputs)) def memory_write(artifact: Artifact, store: dict[str, Artifact]) -> None: # Sink check: fail closed on tainted writes unless quarantined explicitly. if artifact.label == Taint.UNTRUSTED: raise TaintLaunderingError( f"refusing trusted memory write of tainted artifact {artifact.content_hash[:12]}" ) store[artifact.content_hash] = artifact def egress(artifact: Artifact, destination: str) -> None: # Sink check at the tool-egress boundary. if artifact.label == Taint.UNTRUSTED: raise TaintLaunderingError( f"egress to {destination} blocked: artifact {artifact.content_hash[:12]} is tainted" ) def detect_provenance_gap(artifact: Artifact, known_parents: set[str]) -> None: # A recovering transform that dropped parent hashes is a protocol violation. if any(p not in known_parents for p in artifact.parents): raise TaintLaunderingError( f"artifact {artifact.content_hash[:12]} cites unknown parents; " "possible unlogged recovering transform" ) ```