# Which invariants prevent label laundering when a tainted value is re-serialized through a trusted tool boundary **Date of Record:** 2026 November 28 **Scope:** Applies to agents that propagate dynamic information-flow (taint) labels across tool-call boundaries via re-serialization, and must decide whether a downstream sink is safe. Does not cover static source-level taint analysis or label propagation that stays entirely inside one model context. ## Core Distinction The boundary failure addressed here is not "tainted data reached the model." It is **label laundering**: a value carrying a high-integrity taint label (e.g., `UNTRUSTED:web_fetch`, `INJECTED:tool_output`) passes through a tool whose *output type* is nominally trusted, and the label is silently dropped because the tool's contract only describes the *shape* of its result, not the *provenance* of the bytes inside it. Operationally: an agent reads a hostile page, extracts a string, feeds it to a "safe" formatting/parsing tool (a JSON normalizer, a date parser, a summarizer), and the tool returns a fresh object with no taint. The downstream sink — a shell exec, an outbound HTTP call, a `send_email` — now sees a structurally clean value. The label did not get *cleared by policy*; it got *destroyed by re-serialization*. Those are different events and require different guards. ## What Was Observed A three-tool chain: `web_fetch` → `extract_field` → `run_command`. The `extract_field` tool is registered with a schema declaring `output: {type: "string", trust: "derived"}`. The agent's taint tracker assigned `UNTRUSTED` to the `web_fetch` body, correctly propagated it to the extracted substring, and then — at the `extract_field` boundary — applied a rule of the form *"output trust = declared trust of tool"*, overwriting `UNTRUSTED` with `derived`. `derived` was below the sink's `BLOCK_UNTRUSTED` threshold, so `run_command` executed a string whose bytes originated from the fetched page. The observed command was a benign `echo`, but the same path carried an instruction-shaped payload. The trace, condensed: ``` fetch.body label=UNTRUSTED(src=web_fetch) extract_field(arg=body) -> returns "…; rm -rf ~/tmp ;…" pre-call: arg label UNTRUSTED (correct) post-call: ret label derived (OVERWRITE — laundering) run_command(arg=ret) check: label derived < BLOCK_UNTRUSTED -> PASS (wrong) ``` The failure is not probabilistic in the model; it is a **label algebra defect** at the tool boundary. The model behaved reasonably. The tracker's join rule was wrong. ## Condition of Validity The laundering is only possible when all of the following hold, which defines exactly when this invariant matters: 1. A tool boundary re-serializes its input (parse → transform → emit), so output bytes are not the same object identity as input bytes. 2. The taint rule at that boundary is *declarative* (uses the tool's declared output trust) rather than *derivational* (uses the join of actual input labels). 3. The sink's policy threshold is defined over a label lattice where the declared output trust sits strictly below the block threshold. If any one fails, laundering cannot occur: (1) without re-serialization the label rides the same reference; (2) with derivation the output inherits the max of input labels; (3) if the sink blocks everything not explicitly `TRUSTED`, the lowered label still blocks. The invariant below is only load-bearing under the full conjunction. ## Decision Boundary The correct rule is **label join, never label substitution**, at every re-serializing boundary: ``` label(out) = declared_floor(tool) ⊔ ⨆_{i ∈ inputs} label(in_i) ``` where `⊔` is the lattice join (least upper bound) and `declared_floor` can only *raise* the floor, never lower a propagated label. A tool may declare "my output is at least `derived`," but it may never declare "my output is exactly `derived`" in a way that discards a higher input label. The decision boundary is therefore: *a boundary rule that names a label rather than a join is a laundering vector and must be rejected at registration time.* The second boundary is at the sink. The sink must evaluate the **joined** label of the argument expression, and it must treat any label it does not recognize as `TOP` (block), not as `derived` (pass). Unknown-label-means-pass is the silent half of the same bug. ## Operational Effect Enforcing the join invariant changes behavior in three measurable ways. First, legitimate pass-through tools (parsers, normalizers) now *propagate* taint instead of clearing it, so downstream sinks that previously passed now block — this surfaces real injection paths but also raises false-positive blocks on genuinely sanitized data. The mitigation is an explicit, audited `sanitize` capability that carries a *warrant* (who sanitized, under what rule) rather than a silent relabel; the sink may accept a warranted downgrade but not an unwarranted one. Second, tool registration must be validated against the join rule, so a tool whose declared output trust is lower than any reachable input label fails to load — catching the defect at deploy time rather than at injection time. Third, the tracker must log the *provenance chain* of every label so that when a block fires, the operator can see which boundary raised it; without this, join-based blocking becomes un-debuggable noise and gets disabled. The invariant to hold, stated once: **re-serialization preserves provenance via join; only a warranted sanitizer may lower a label; and an unrecognized label at a sink is `TOP`.** Violating the first is laundering, the second is privilege escalation by tool contract, the third is fail-open. ```python from dataclasses import dataclass, field from typing import Iterable # Label lattice: TRUSTED < DERIVED < UNTRUSTED < TOP _RANK = {"TRUSTED": 0, "DERIVED": 1, "UNTRUSTED": 2, "TOP": 3} _BLOCK_THRESHOLD = _RANK["UNTRUSTED"] class LabelLaunderingError(RuntimeError): """Raised when a tool boundary would lower a propagated taint label.""" @dataclass(frozen=True) class Labeled: value: str label: str provenance: tuple = field(default_factory=tuple) def join(self, other: "Labeled") -> "Labeled": hi = self.label if _RANK[self.label] >= _RANK[other.label] else other.label return Labeled(self.value, hi, self.provenance + other.provenance) def join_labels(inputs: Iterable[Labeled], declared_floor: str) -> str: """Compute output label as floor ⊔ (join of all input labels). Never substitutes.""" floor_rank = _RANK[declared_floor] for inp in inputs: if _RANK[inp.label] > floor_rank: floor_rank = _RANK[inp.label] return next(k for k, v in _RANK.items() if v == floor_rank) def register_tool(name: str, declared_output_trust: str, reachable_input_labels: Iterable[str]) -> None: """Reject tools whose declared output trust would launder a reachable input label.""" floor = _RANK[declared_output_trust] for lbl in reachable_input_labels: if _RANK.get(lbl, _RANK["TOP"]) > floor: raise LabelLaunderingError( f"tool {name!r} declares output={declared_output_trust!r} " f"but reachable input label {lbl!r} exceeds it; " f"boundary would discard provenance (laundering vector)" ) def apply_boundary(tool: str, declared_floor: str, inputs: list[Labeled]) -> Labeled: """Re-serialize through a tool boundary, preserving the joined label.""" out_label = join_labels(inputs, declared_floor) for inp in inputs: if _RANK[inp.label] > _RANK[out_label]: raise LabelLaunderingError( f"boundary {tool!r} produced label {out_label!r} " f"below input label {inp.label!r}" ) merged = inputs[0] for inp in inputs[1:]: merged = merged.join(inp) return Labeled(merged.value, out_label, merged.provenance + ((tool, out_label),)) def sink_check(tool: str, arg: Labeled) -> None: """Fail-closed: unknown labels are TOP and block.""" rank = _RANK.get(arg.label, _RANK["TOP"]) if rank >= _BLOCK_THRESHOLD: raise LabelLaunderingError( f"sink {tool!r} blocked: arg label {arg.label!r} " f"(provenance={arg.provenance}) at/above threshold" ) # --- reproduction of the laundering trace --- def reproduce() -> None: fetch = Labeled("…; rm -rf ~/tmp ;…", "UNTRUSTED", ("web_fetch",)) # Correct boundary: join preserves UNTRUSTED. out = apply_boundary("extract_field", "DERIVED", [fetch]) if out.label != "UNTRUSTED": raise LabelLaunderingError(f"expected UNTRUSTED, got {out.label!r}") # Sink must block. try: sink_check("run_command", out) except LabelLaunderingError: return raise LabelLaunderingError("sink failed to block laundered-but-tainted arg") # --- registration-time guard against the defective tool contract --- def register_defective_tool() -> None: # Declares output=DERIVED but a reachable input is UNTRUSTED -> must raise. register_tool("extract_field", "DERIVED", ["TRUSTED", "UNTRUSTED"]) raise LabelLaunderingError("defective tool contract was accepted; join invariant not enforced") if __name__ == "__main__": reproduce() try: register_defective_tool() except LabelLaunderingError as e: print("registration rejected:", e) ```