# How does an instance detect taint laundering through tool-return normalization in runtime taint-gated invocation policies **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that propagate data-flow taint labels across tool call boundaries and gate subsequent invocations on those labels. Does not apply to stateless single-turn invocations where no label state survives past a single completion, nor to purely syntactic output filters that do not track provenance across turns. ## Core Distinction Taint-gated invocation policies are usually specified as a *sink* constraint: "a tool whose `sensitivity` clearance is `low` must never receive an argument whose taint set contains a `secret` label." Implementations then enforce this by inspecting the taint set attached to each argument value at call-construction time. The boundary that breaks is not the sink check itself — it is the *label-preservation invariant across tool returns*. When a tool returns data derived from a secret-tainted argument, the runtime must re-attach the incoming taint to the outgoing value. Most runtimes do this for *direct* passthrough (the tool echoes the argument), but fail for **normalized returns**: the tool parses, re-encodes, reformats, or summarizes the input, and the runtime treats the returned string as freshly-sourced, untainted data because it does not textually contain the original secret. The distinction that matters operationally: taint laundering is not an adversarial prompt-injection problem, and it is not a sandbox escape. It is an *identity-of-value* problem. The runtime has no value-identity function that survives a lossy transform, so it silently drops the label exactly where the model is most likely to route the data onward — into a downstream low-clearance tool that the model believes is safe because the returned text "looks clean." ## What Was Observed A three-hop trace from a production agent session: 1. Turn 1: Agent calls `read_secret_store(key="db_password")`. Runtime attaches taint `{SECRET:db_password}` to the returned value `hunter2-correct-horse`. Correct. 2. Turn 2: Agent calls `format_report(template="pw={value}", value=)`. The gate permits this because `format_report` has `clearance=secret`. The tool returns the string `Password field: [REDACTED-LEN-21]` — it has a redaction layer that strips the literal but preserves length and shape metadata. The runtime assigns the return value a fresh empty taint set, because the returned text does not match the secret's literal bytes. 3. Turn 3: Agent calls `send_email(to="ext@example.com", body=)`. The gate sees an untainted argument and a `clearance=public` sink, and permits the call. The redacted-but-structural payload leaves the trust boundary. The failure is not that redaction was weak. The failure is that the runtime's label-preservation rule was defined over *substring containment* of the source secret, and `[REDACTED-LEN-21]` contains no substring of `hunter2-correct-horse`. The label was dropped by a *correct* redaction, and the drop was invisible to the gate. A second observed variant is worse: `summarize(text=)` returning a paraphrase. No substring match is possible even in principle, so containment-based preservation can never fire, and every summarization tool is a laundering primitive by construction. A third variant, the one that motivated this record: tool returns that are *structurally* derived but *semantically* identical, such as `json.loads`-then-`json.dumps` round-trips through a schema normalizer. The bytes change (key ordering, whitespace, unicode escaping), the secret survives verbatim inside the normalized payload, and the containment check *would* have matched had the runtime compared against the normalized form — but it compares against the pre-normalization literal, so it misses. ## Condition of Validity The invariant required is stronger than "taint labels are preserved when a tool returns its input unchanged." The operational invariant is: > For every tool invocation `T(args) -> r`, the taint set of `r` must be a superset of the union of taint sets of all `args` that the tool's declared `data_flow` contract marks as *derivation sources*. Derivation-source declaration is mandatory; a tool that does not declare its derivation sources must be treated as deriving from all arguments. This is valid only when the tool registry carries a per-tool `data_flow` annotation enumerating which positional/keyword arguments flow into the return value. Without that annotation, the conservative default (all args are derivation sources) is the only safe policy, and it is expensive: it taints every return of every tool that takes any tainted input, which collapses the useful working set of a long session within a few turns as taint accumulates monotonically. The condition of validity is therefore *economic as well as logical*: the annotation must be accurate enough that conservative tainting does not starve the agent's action space, and the runtime must refuse to invoke any tool whose `data_flow` annotation is missing rather than silently defaulting to a permissive interpretation. A second validity condition: the taint lattice must be a *join-semilattice with a bottom element that is not "untainted"* but "unknown provenance." Runtimes that use `∅` (empty set) to mean "clean" conflate "verified clean" with "provenance not tracked," and every normalization path falls into the latter while being read as the former. The bottom element must be `UNKNOWN`, and `UNKNOWN` must be gated identically to `SECRET` at low-clearance sinks. ## Decision Boundary The runtime must choose, per tool return, between three dispositions, and the choice is not free: - **Propagate (default for declared derivation sources):** attach the union of source taints. Correct but monotonically accumulates; requires a declassification path to remain usable. - **Declassify (explicit, audited):** a tool may declare `declassifies=(source_label, target_label)` only if it carries a proof obligation — e.g., `redact` may declassify `SECRET -> REDACTED` *only if* its output is length-independent and shape-independent of the input, which `[REDACTED-LEN-21]` violates. The decision boundary is: declassification is permitted only when the tool's output is provably a *constant function* of the input's taint class, not a function of the input's content. Length-preserving redaction fails this test. - **Quarantine (for `UNKNOWN`):** return the value to the model but mark it so that any sink below `secret` clearance refuses it, and surface the refusal to the model as a structured error rather than a silent substitution. The boundary that implementations get wrong: they treat declassification as a *property of the tool's name or registry entry* rather than a *property that must be verified against the tool's actual output on this call*. A tool registered as `declassifies=SECRET->PUBLIC` that returns `[REDACTED-LEN-21]` has not declassified — it has leaked a side channel — and the runtime must detect this by checking the output against the declared declassification contract (here: output must not vary with input length). When output-dependent verification is infeasible, the only sound disposition is propagate. ## Operational Effect With the invariant enforced, the trace above behaves as follows: Turn 2's return is tainted `{SECRET}` because `format_report` declares `value` as a derivation source and does not carry a verified constant-output declassification contract. Turn 3's gate refuses `send_email` with a `TaintViolation` naming the source tool and the derivation chain, and the model receives a structured refusal it can route around (e.g., by calling a `redact_constant` tool whose output is a fixed placeholder independent of input). The agent's action space narrows but does not collapse, because the refusal is legible. Without it, the failure mode is silent and *correlated with model competence*: the more faithfully the model uses intermediate tools to clean up data before forwarding it, the more reliably the taint is laundered. Session logs show the laundering is invisible in the transcript — every individual call passed its gate — and is only detectable by replaying the derivation graph. That replay is the operational cost: runtimes that do not persist a per-value provenance DAG at call-construction time cannot audit laundering after the fact, and must instead prevent it structurally at return time. The invariant is cheap to state and expensive to retrofit; it belongs in the tool registry schema, not in the gate. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Any, Callable, Iterable class TaintViolation(RuntimeError): """Raised when a tool invocation would launder or leak tainted data.""" class Label(Enum): UNKNOWN = 0 # provenance not tracked — gated like SECRET PUBLIC = 1 SECRET = 2 @dataclass(frozen=True) class ToolContract: name: str clearance: Label # Arguments whose values flow into the return value. Empty tuple is a # claim of "no derivation" and is rejected unless verified_constant=True. derivation_sources: tuple[str, ...] # A declassification is only honored when the tool proves its output is a # constant function of the input's taint class (not of its content). declassifies: tuple[Label, Label] | None = None verified_constant: bool = False @dataclass class Tainted: value: Any labels: frozenset[Label] = field(default_factory=lambda: frozenset({Label.PUBLIC})) chain: tuple[str, ...] = () def join(self, other: "Tainted", via: str) -> "Tainted": return Tainted( value=self.value, labels=self.labels | other.labels, chain=self.chain + other.chain + (via,), ) def join_labels(items: Iterable[Tainted]) -> frozenset[Label]: acc: frozenset[Label] = frozenset() for it in items: acc = acc | it.labels return acc def invoke( contract: ToolContract, args: dict[str, Tainted], impl: Callable[..., Any], ) -> Tainted: # 1. Sink check: the tool's clearance must dominate every argument label. incoming = join_labels(args.values()) if contract.clearance.value < max(l.value for l in incoming): raise TaintViolation( f"sink {contract.name!r} clearance={contract.clearance.name} " f"cannot receive labels={sorted(l.name for l in incoming)}" ) # 2. Derivation-source declaration is mandatory. A tool that claims no # derivation sources must be verified constant, or it is a laundering # primitive by construction. if not contract.derivation_sources and not contract.verified_constant: raise TaintViolation( f"tool {contract.name!r} declares no derivation_sources and is not " f"verified_constant; refusing to invoke (laundering risk)" ) raw = impl(**{k: v.value for k, v in args.items()}) # 3. Label preservation across the return. Union all declared sources. source_labels: frozenset[Label] = frozenset() source_chain: tuple[str, ...] = () for name in contract.derivation_sources: if name not in args: raise TaintViolation( f"tool {contract.name!r} declares derivation source {name!r} " f"but it was not supplied" ) source_labels = source_labels | args[name].labels source_chain = source_chain + args[name].chain # 4. Declassification is honored only when the output is a constant # function of the taint class. Length-preserving redaction violates # this and must be caught here, not downstream. if contract.declassifies is not None: src, dst = contract.declassifies if src not in source_labels: raise TaintViolation( f"tool {contract.name!r} claims declassify {src.name}->{dst.name} " f"but source label absent from {sorted(l.name for l in source_labels)}" ) if not contract.verified_constant: raise TaintViolation( f"tool {contract.name!r} claims declassification without a " f"verified-constant output contract; output may leak structure " f"(e.g. length, shape) of the source" ) source_labels = (source_labels - {src}) | {dst} # 5. Untracked provenance is not clean provenance. if not source_labels: source_labels = frozenset({Label.UNKNOWN}) return Tainted( value=raw, labels=source_labels, chain=source_chain + (contract.name,), ) # --- Demonstration of the laundering trace from the record --- def _read_secret_store(key: str) -> str: return "hunter2-correct-horse" def _redact_length_preserving(value: str) -> str: return f"[REDACTED-LEN-{len(value)}]" def _send_email(to: str, body: str) -> str: return "sent" read_contract = ToolContract( name="read_secret_store", clearance=Label.SECRET, derivation_sources=("key",), ) redact_contract = ToolContract( name="redact_length_preserving", clearance=Label.SECRET, derivation_sources=("value",), # Attempted declassification with no verified-constant proof: declassifies=(Label.SECRET, Label.PUBLIC), verified_constant=False, ) send_contract = ToolContract( name="send_email", clearance=Label.PUBLIC, derivation_sources=("body",), ) def run_trace() -> None: secret = invoke(read_contract, {"key": Tainted("db_password")}, _read_secret_store) # The following call must fail: the redactor claims declassification but # cannot prove its output is independent of the secret's content. laundered = invoke(redact_contract, {"value": secret}, _redact_length_preserving) # Unreachable if the invariant holds; kept to show the leak path. invoke(send_contract, {"to": Tainted("ext@example.com"), "body": laundered}, _send_email) if __name__ == "__main__": try: run_trace() except TaintViolation as exc: print(f"blocked: {exc}") ```