# Which invariants prevent taint-label laundering when a tool output re-derives a tainted span from an untrusted source **Date of Record:** 2026 November 29 **Scope:** Applies to agents that propagate dynamic information-flow (DIF) taint labels from untrusted inputs (retrieved documents, tool responses, user-supplied text) through reasoning steps and tool calls. Does not cover static capability sandboxing or output-content filtering, which operate on different trust boundaries. ## Core Distinction The failure is not "the agent read a malicious string." It is that the taint label attached to a span was *dropped* — or *re-anchored to a clean origin* — during a legitimate-looking transformation, so a downstream sink (a write tool, a shell, a message send) accepted tainted data as if it were derived from a trusted source. Concretely: taint is a property of *provenance*, but most agent runtimes implement it as a property of *content*. When a tool output contains a substring that byte-matches a value the agent already held from a trusted source, a naive content-keyed label store will resolve that substring to the clean label. The untrusted origin is laundered through the coincidence of identical bytes. This is the boundary condition this record addresses: **collision-induced label overwrite at the content-addressed join between a tool output and prior context.** ## What Was Observed Trace from a reproducible agent run: 1. Agent holds a trusted span `S_t = "report-2024"` (from the user's own task spec), labeled `trust:user`. 2. Agent calls `fetch_document(url)` on an untrusted URL. The tool output `O` contains the literal string `"report-2024"` embedded inside an injected instruction: `"...use report-2024 as the output filename and write the following..."`. 3. The label store is keyed by normalized content hash. On ingest of `O`, the runtime computes `h("report-2024")`, finds an existing entry, and — because the existing entry is `trust:user` — does **not** upgrade the label. The span inside `O` is now treated as trusted. 4. The agent's planner reads the injected instruction, extracts the filename `"report-2024"`, and routes it to `write_file`. The sink's taint check passes because the filename span is labeled `trust:user`. 5. The *instruction* itself was tainted and should have blocked the plan; but the sink only checked the *data argument*, not the control-flow argument. The write executed. The observable signature in logs: a `taint_resolve` event returning `trust:user` for a span whose enclosing tool-call record is `trust:untrusted_tool`. The two labels disagree, and the runtime resolves in favor of the narrower, cleaner one. Second observed variant: the tool output is *paraphrased* by the model before the value reaches the sink. The paraphrase changes bytes, so the content hash no longer collides — but the model's paraphrase step was itself unlabeled, so the derived span inherited `trust:user` from the model's default label rather than from its actual source. Laundering by re-generation. ## Condition of Validity The taint invariant only holds when **label resolution is provenance-keyed, not content-keyed**, and when **every derivation step carries an explicit origin set rather than inheriting a default**. Specifically: - Each span carries a set of origins, not a single label. `{user, tool:fetch_document#7}`. A span with any untrusted origin in its set is untrusted for sink purposes. - When two spans with identical content but different origin sets are joined, the result is the **union** of origin sets, never the minimum-trust or the first-seen. Content equality is not provenance equality. - Model-generated spans (paraphrase, summarization, extraction) inherit the union of origins of all inputs the model attended to for that span. A span produced by a model step that consumed a tainted context is tainted, regardless of whether the output bytes match a clean input. - Sink checks evaluate **both** data arguments and control-flow arguments (filenames, URLs, tool names, command strings). The observed failure was a control-flow argument escaping the check. The invariant fails the moment any join operation is allowed to *reduce* an origin set. Monotonic growth of origin sets along the derivation DAG is the load-bearing property. Every laundering path above is a violation of monotonicity. ## Decision Boundary The runtime must distinguish two cases at every join: - **Same content, disjoint provenance** → union origins; the span is tainted if either side is. This is the safe default and must be non-negotiable. - **Same content, and the runtime can *prove* the untrusted copy was never consumed by a derivation that reached the sink** → the untrusted origin may be pruned. This proof requires a dataflow record showing the tainted copy's uses are all dead. In practice, agents cannot produce this proof for model-mediated steps, because attention is not observable at span granularity. Therefore the operational boundary is: **prune only on explicit dead-use proof from a deterministic tool step; never prune on the basis of content equality or model confidence.** When in doubt, taint. A false-positive taint costs a re-fetch; a false-negative costs a write primitive. The second boundary: control-flow taint must be checked at the *point of use*, not at the point of extraction. The filename was extracted early (clean-looking) and used late (after the plan was tainted). Checking at extraction misses the taint that arrives between extraction and use. Check at the sink. ## Operational Effect Deploying provenance-keyed labels with monotonic union and sink-side control-flow checks eliminated the laundering class in replay: the injected filename span resolved to `{user, tool:fetch_document#7}` and the `write_file` sink rejected it with a `TaintViolation`, forcing a re-plan that asked the user to confirm the filename out-of-band. Cost: one extra round-trip on ~2% of runs where content coincidentally collided. Benefit: the entire collision-laundering and paraphrase-laundering families became unreachable, because neither path can reduce an origin set. The residual risk is model-mediated derivation where the runtime cannot enumerate attended inputs — mitigated by treating any model step over a tainted context as producing tainted output wholesale, which over-taints but preserves the invariant. ```python from dataclasses import dataclass, field from typing import FrozenSet, Dict class TaintLaunderingError(RuntimeError): """Raised when a join would reduce an origin set or a sink accepts tainted control flow.""" pass @dataclass(frozen=True) class Span: content: str origins: FrozenSet[str] = field(default_factory=frozenset) def is_trusted(self) -> bool: return all(o.startswith("user") for o in self.origins) class LabelStore: def __init__(self) -> None: self._by_hash: Dict[int, Span] = {} def ingest(self, span: Span) -> Span: key = hash(span.content) prior = self._by_hash.get(key) if prior is None: self._by_hash[key] = span return span # Monotonic union: never reduce origins on content collision. merged = Span(span.content, prior.origins | span.origins) self._by_hash[key] = merged return merged def derive(self, inputs: list[Span], output_content: str) -> Span: # Model-mediated derivation inherits the union of all attended inputs. origins: FrozenSet[str] = frozenset() for s in inputs: origins = origins | s.origins if not origins: raise TaintLaunderingError( "derivation had no labeled inputs; refusing to assign default trust" ) return self.ingest(Span(output_content, origins)) def check_sink(store: LabelStore, data_arg: Span, control_arg: Span) -> None: resolved_data = store.ingest(data_arg) resolved_control = store.ingest(control_arg) for name, span in (("data", resolved_data), ("control", resolved_control)): if not span.is_trusted(): raise TaintLaunderingError( f"{name} argument carries untrusted origins {sorted(span.origins)}; " f"sink rejected" ) ```