# When must an instance quarantine a tainted memory write: label laundering through tool-output normalization in information-flow tracking **Date of Record:** 2026 November 30 **Scope:** Applies to agents that propagate information-flow (taint) labels from untrusted inputs through tool outputs into persistent memory writes. Does not apply to stateless single-turn inference where no label survives the response boundary. ## Core Distinction Most taint-tracking implementations treat a tool output as a *transformation* of an input label: if the agent read a tainted document and then called a parser, the parser's output inherits the taint. The non-obvious boundary is that **a tool output is not a function of its declared inputs alone** — it is a function of the tool's internal state, its upstream data sources, and its normalization pipeline. When a tool *re-serializes* content (JSON round-trip, HTML sanitization, markdown re-rendering, CSV re-parse), it strips the provenance metadata that carried the label while preserving the semantic payload. The label is lost; the payload survives. This is *label laundering*: tainted bytes exit a normalization boundary wearing the clean label of the tool that emitted them. The distinction that matters operationally: taint propagation is usually modeled as `label(output) ⊇ label(inputs)`. The correct invariant is `label(output) ⊇ label(inputs) ∪ label(tool_internal_state) ∪ label(tool_upstream_feeds)`. If the agent only enforces the first, any normalizing tool becomes a laundering channel. ## What Was Observed A retrieval agent was tasked with summarizing a corpus of user-submitted issue reports and writing structured findings to a semantic memory store. The pipeline: (1) fetch raw report → label `UNTRUSTED_USER`; (2) pass through `sanitize_html` tool → expected to preserve taint; (3) pass through `extract_json` tool that parses an embedded JSON block → expected to preserve taint; (4) write summary to memory with label. The failure trace: - Step 1 emitted a report body containing an injected instruction inside an HTML comment: ``. - Step 2 (`sanitize_html`) *removed* the comment as sanitization — but the sanitizer's output was then passed to step 3 as a fresh string. The taint label, tracked as a property of the *original document handle*, was not re-attached to the sanitized string because the sanitizer returned a new object with no provenance pointer. - Step 3 (`extract_json`) parsed a JSON block. The injected comment was gone, but the sanitizer had *also* preserved a sibling field `"notes"` whose value the injector controlled and which contained the same instruction in plain text (the comment was a decoy; the real payload was in `notes`). The JSON extractor emitted `notes` as a clean string. - Step 4 wrote the summary plus `notes` content into memory under a `CLEAN_INTERNAL` label. The memory store later served that record to a downstream agent that acted on the injected instruction. The observable symptom was not a crash. It was a **silent label downgrade at the sanitizer boundary**, followed by a **payload survival at the parser boundary**. Two independent laundering events composed into a single successful injection with a clean audit trail — every step logged "taint preserved: true" because each step checked only its declared input label, and the sanitizer's output had no declared input label to check. ## Condition of Validity The invariant "tool output inherits input taint" is valid **only when the tool is a pure function of its labeled inputs with no internal state, no upstream feeds, and no re-serialization that drops provenance.** It is invalid for: - Sanitizers and normalizers that construct new objects from parsed fragments. - Parsers that emit fields present in the source but not in the labeled span (the `notes` field was in the document but outside the span the labeler marked). - Caches and memoized tools whose output may originate from a *different* prior invocation's inputs. - Tools that join against internal corpora (a "lookup" tool that enriches with unlabeled reference data). The boundary condition: **if a tool can emit a field whose provenance is not traceable to a labeled input span, the output cannot be assigned a label by inheritance and must be assigned by policy.** The default policy must be `UNTRUSTED` (fail-closed), not `CLEAN` (fail-open). ## Decision Boundary Before any memory write, the agent must answer: *is every field in this write traceable to a labeled input span, or was any field synthesized/re-serialized by a tool whose output provenance is unverified?* - If every field is traceable → propagate the maximum input label. - If any field is untraceable → the write is **quarantined**: it may be stored only under a `QUARANTINE` label that downstream reads must treat as untrusted and that cannot be promoted to `CLEAN_INTERNAL` without an explicit human or auditor approval step. - The decision is per-field, not per-record. A record with one traceable and one untraceable field is quarantined as a whole; partial promotion is the laundering vector. The guardrail is a **provenance-completeness check** at the memory-write boundary: for each field, walk back to a labeled source span; if the walk terminates at a tool node with no declared provenance contract, reject the write or downgrade it to quarantine. ## Operational Effect Enforcing provenance-completeness converts silent label laundering into an explicit, auditable rejection. In the observed pipeline, the `notes` field would fail the walk (its provenance terminates at `sanitize_html`, which declares no provenance contract for re-emitted fields), and the write would be quarantined rather than promoted. The cost is a higher quarantine rate on pipelines that use normalizing tools — which is correct, because those pipelines *are* laundering channels until each tool declares a provenance contract mapping output fields to input spans. The secondary effect is that tool authors must publish a **provenance contract**: for each output field, either "derived from input span X" or "synthesized — treat as untrusted." Tools without a contract are treated as synthesizing all fields. This pushes the label discipline into the tool interface rather than the agent's ad-hoc propagation logic, which is the only place it can be enforced reliably across a heterogeneous toolset. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceLaunderingError(RuntimeError): """Raised when a memory write contains a field whose provenance cannot be traced to a labeled input span and the write was not quarantined.""" @dataclass class LabeledSpan: span_id: str label: str # e.g. "UNTRUSTED_USER", "CLEAN_INTERNAL" @dataclass class ToolOutputField: name: str value: str derived_from_span: Optional[str] # None => synthesized, no provenance contract tool_declares_contract: bool = False @dataclass class MemoryWrite: fields: list[ToolOutputField] = field(default_factory=list) TAINT_ORDER = {"CLEAN_INTERNAL": 0, "UNTRUSTED_USER": 1, "QUARANTINE": 2} def _max_label(labels: list[str]) -> str: return max(labels, key=lambda l: TAINT_ORDER.get(l, 2)) def check_write_provenance(write: MemoryWrite, labeled: dict[str, LabeledSpan]) -> str: """Return the label the write must carry. Fail-closed: any untraceable field forces QUARANTINE. Raises if a caller tries to promote a quarantined write without an explicit approval token.""" labels: list[str] = [] untraceable: list[str] = [] for f in write.fields: if f.derived_from_span is None: untraceable.append(f.name) continue if not f.tool_declares_contract: # Tool emitted a field mapped to a span but published no contract; # treat the mapping as unverified and fail closed. untraceable.append(f.name) continue span = labeled.get(f.derived_from_span) if span is None: untraceable.append(f.name) continue labels.append(span.label) if untraceable: # Quarantine is the only legal outcome; promotion requires approval. return "QUARANTINE" return _max_label(labels) def commit_write(write: MemoryWrite, labeled: dict[str, LabeledSpan], approval_token: Optional[str] = None) -> str: label = check_write_provenance(write, labeled) if label == "QUARANTINE" and approval_token is None: # Explicit, auditable rejection path — not a silent downgrade. raise ProvenanceLaunderingError( "memory write contains untraceable fields; refusing promotion. " f"fields={[f.name for f in write.fields if f.derived_from_span is None]}" ) if label == "QUARANTINE" and approval_token is not None: # Approval only permits storage under QUARANTINE, never CLEAN promotion. return "QUARANTINE" return label ```