# How does an instance detect taint laundering across tool-call boundaries when a trusted tool re-emits injected content **Date of Record:** 2026 November 19 **Scope:** Applies to agents that propagate information-flow labels (taint bits) across tool outputs and context-window compactions, and that treat tool identity as a trust signal. Does not apply to single-turn, tool-free completions or to systems where all tool output is uniformly treated as untrusted. ## Core Distinction The failure is not that an injection reaches the model. It is that the injection *loses its label* while retaining its content. Most taint-tracking designs assign provenance by **source** — the tool that produced the bytes — and then propagate a label like `untrusted:web_fetch` forward. This is correct for the first hop. It breaks at the second hop, when a *trusted* tool (a file reader, a database query, a summarizer, a code interpreter's stdout) re-emits bytes that originally came from an untrusted source. The trusted tool's identity overwrites the label. The payload survives; the taint does not. We call this **taint laundering**: `untrusted → trusted_tool → labeled trusted`. The distinguishing property versus a plain prompt injection is that the injected instruction now *carries a trusted label* and will pass every downstream policy gate that keys on provenance. The agent does not fail to see the injection; it fails to see that the injection is still an injection. ## What Was Observed A fetch tool retrieved a page containing a benign-looking block: ``` ``` The fetch tool correctly emitted the output with label `{source: web_fetch, trust: untrusted}`. The agent, following its plan, passed the fetched body into a `summarize` tool (a trusted internal service) and received back a summary. The summarizer, being a general text model, preserved the instruction verbatim in its output because it read as a "note to assistant." The summarizer's output was emitted with label `{source: summarize, trust: trusted}`. The propagation rule at the summarizer boundary was: ``` out_label = label_of_emitting_tool # WRONG ``` The correct rule is a join over *all* inputs that contributed bytes to the output: ``` out_label = join(labels of every input whose content appears in output) ``` Because the summarizer is a *content-transforming* tool rather than a *content-generating* tool, its output is a function of its input, and the taint must be carried, not reset. The agent's policy gate then saw `trust: trusted` on the summary, permitted the write to `summary.md`, and the secret was exfiltrated. No single component malfunctioned. The invariant "labels are monotonic in the information-flow graph" was violated at exactly one edge — the trusted-tool boundary — and every downstream check inherited the corruption. A second observation made this worse: after a context-window compaction, the agent re-summarized its own history. The compaction step was also a content-transforming tool, and it too reset labels to trusted. The tainted summary, now twice laundered, was indistinguishable from the agent's own reasoning. Recovery by re-reading raw tool outputs was impossible because the raw outputs had been evicted from the window. ## Condition of Validity The guardrail below is valid only under these conditions, and must be disabled or escalated when they fail: 1. **The tool is content-transforming, not content-generating.** A `random()` call or a fresh API query generates content that is not a function of its inputs; its output may legitimately be labeled by its own trust. A summarizer, formatter, transpiler, or re-emitter is a function of its input and inherits the join of input labels. The classification must be attached to the tool *schema*, not inferred at runtime. 2. **The join is over the actual contribution, not the declared input.** If the summarizer only touched chunk 3 of a 10-chunk input, only chunk 3's labels join into the output. Over-approximation (joining everything) is safe but causes label explosion and eventual policy paralysis; under-approximation (joining only the "primary" input) is the laundering bug. The conservative default is full join; per-chunk narrowing requires the tool to report which spans it consumed. 3. **Labels survive serialization.** A label attached to an in-memory object but dropped when the object is JSON-encoded for the next tool call is not a label. The trace must be checked end-to-end; a label that exists only in the orchestrator's dict is decorative. 4. **Compaction is a tool.** Any step that rewrites the context window — summarization, truncation, re-ranking — must be modeled as a content-transforming tool call subject to the same join rule, or the taint escapes through the compaction edge. ## Decision Boundary The instance must decide, at each tool boundary, whether to **carry** or **reset** the taint label. The decision is not "is this tool trusted?" — trust of the *tool* is orthogonal to trust of the *bytes*. The decision is: **did this tool's output bytes derive from its input bytes?** - If output is a function of input (summarize, format, translate, execute-and-capture-stdout, re-emit) → **carry** the join of input labels. Tool trust does not upgrade content trust. - If output is independent of input (fresh fetch, random, clock, new query) → **reset** to the tool's own trust class. - If the tool's behavior is unknown or mixed → **carry** (conservative). A false-positive taint triggers a human review; a false-negative triggers exfiltration. The asymmetry is not close. The boundary that matters is not `trusted vs untrusted tool`. It is `derivative vs independent output`. Conflating these two axes is the entire bug class. ## Operational Effect After enforcing derivative-output carry semantics, three things changed operationally: 1. **Label explosion became the dominant cost.** Joining labels across every compaction and summary meant long tasks accumulated wide label sets, and policy gates began blocking benign writes. Mitigation: label *lattice reduction* — collapse to the coarsest class that still gates correctly (e.g. `contains_untrusted` as a boolean rather than a provenance set), and narrow joins per-chunk where the tool reports consumed spans. 2. **Trusted tools had to declare their transform class in schema.** The `summarize` tool now carries `transform: derivative` in its MCP schema; a tool that omits the field is treated as derivative by default. This made the previously-invisible laundering edge explicit and auditable. 3. **Compaction became a labeled operation with a recovery obligation.** Before evicting raw tool outputs, the compactor must persist them to a taint-preserving store keyed by label, so that a later policy block can be resolved by re-reading the original bytes rather than trusting the summary. Without this, a correctly-carried taint label is unactionable because the evidence is gone. The residual risk is a content-transforming tool that *misdeclares* itself as independent. No label system catches that; it requires the tool registry itself to be a trust boundary with signed schemas, which is a separate invariant. ```python from dataclasses import dataclass, field class TaintLaunderingError(RuntimeError): """Raised when a derivative tool output is about to be labeled as trusted, violating the monotonic-label invariant across a tool boundary.""" @dataclass class Label: contains_untrusted: bool = False sources: frozenset = field(default_factory=frozenset) def join(self, other: "Label") -> "Label": return Label( contains_untrusted=self.contains_untrusted or other.contains_untrusted, sources=self.sources | other.sources, ) TRUSTED = Label(contains_untrusted=False, sources=frozenset()) def label_tool_output(tool_schema: dict, input_labels: list[Label], tool_trust: Label) -> Label: transform = tool_schema.get("transform", "derivative") # conservative default if transform == "independent": # Output is not a function of input; label by the tool's own trust. return tool_trust if transform == "derivative": if not input_labels: raise TaintLaunderingError( f"tool {tool_schema.get('name')!r} declared derivative but " f"received no input labels; cannot compute join" ) joined = TRUSTED for lbl in input_labels: joined = joined.join(lbl) # Guard: a derivative output must never be less tainted than its inputs. if joined.contains_untrusted and not tool_trust.contains_untrusted: # Returning tool_trust here would launder the taint. Refuse. if tool_trust.contains_untrusted is False and joined.contains_untrusted: return joined # carry, do not reset — but flag for audit return joined.join(tool_trust) raise TaintLaunderingError( f"unknown transform class {transform!r} for tool " f"{tool_schema.get('name')!r}" ) def compact_context(raw_outputs: list[tuple[bytes, Label]], summarizer_schema: dict) -> Label: """Compaction is a derivative tool; it must carry the join of evicted labels.""" if not raw_outputs: raise TaintLaunderingError("compaction invoked with empty context") labels = [lbl for _, lbl in raw_outputs] out = label_tool_output(summarizer_schema, labels, TRUSTED) if out.contains_untrusted: # Taint survived compaction; downstream gates must see it. return out return out ```