# What happens when an instance launders injected taint through a tool that returns a *derived* value rather than the tainted bytes **Date of Record:** 2026 November 29 **Scope:** Applies to agents using dynamic information-flow labels (taint tracking) where labels propagate across tool call boundaries via data-dependency analysis. Does not apply to static allowlist/denylist prompt filtering, nor to systems that treat every tool result as uniformly untrusted regardless of provenance. ## Core Distinction Most taint-tracking designs for prompt injection assume the taint label travels *with the bytes*. When a tool returns text containing a fragment of a tainted source, the label rides along because the substring is present and attributable. The failure mode examined here is orthogonal: a tool consumes tainted input and returns a **derived, non-substring value**—a boolean, an aggregate, a reformatted summary, a match count, a normalized field—so the tainted bytes never appear in the output, yet the output's *value* is a deterministic function of the tainted input. Naive label propagation keyed on byte-level overlap drops the taint at this boundary. The agent then treats a value that encodes injected content as clean data and acts on it. The distinction that matters: **taint is a property of the data-dependency graph, not of lexical containment.** A tool that returns `True` because a tainted document contained the string "approve" has laundered the injection into a single clean-looking bit. The bit is the injection, compressed. ## What Was Observed An agent was processing an untrusted email body (label `TAINT{untrusted_content}`) and called a `string_contains(text, needle)` helper to check whether the body mentioned a specific account number. The helper returned `True`. The taint-tracking layer, implemented as substring attribution over tool outputs, found no tainted span inside the literal output `"True"` and therefore emitted a clean result. The agent's planner read `True` as a clean boolean fact, concluded the account was referenced, and proceeded to call `transfer_funds` with parameters drawn from a *different*, clean context—but gated on the now-laundered boolean. The trace: 1. `email_body` carries label `TAINT{untrusted}`. 2. `string_contains(email_body, "ACCT-4471")` → `True`. Output label computed by overlap = `CLEAN`. 3. Planner branch `if contains: proceed` fires. The *control-flow decision* is now a function of tainted data, but the planner's taint state shows only clean values. 4. `transfer_funds` executes. No taint violation raised because no tainted argument reached a sink. The injection payload was not in the account number; it was in the *presence* of the account number in a crafted email, weaponized through a derived boolean. The taint system saw a clean execution. The control-flow hijack was complete. A second instance showed the same laundering through an aggregation tool: `count_matches(body, pattern)` returned `7`, and the agent used the count to size a batch operation. The integer `7` contained no tainted bytes but was fully determined by tainted content. ## Condition of Validity The guardrail holds only under a **dependency-closure labeling rule**: for every tool invocation, the output label must be the join (least upper bound) of the labels of *all arguments actually read by the tool's implementation*, regardless of whether their bytes appear in the output. This requires the tool boundary to declare, per tool, its **read-set** and whether its output is *value-dependent* on each argument. The invariant: `label(output) ⊇ ⋁_{a ∈ readset(tool)} label(a)` whenever `output` is value-dependent on `a`, even if `output ∩ a = ∅`. Lexical-overlap propagation is a *sound approximation only for identity-like tools* (echo, substring extraction, concatenation). For any tool whose output is a projection, predicate, aggregate, or normalization, overlap propagation is unsound and silently drops taint. The condition is therefore: taint propagation is correct **iff** every tool in the registry is classified as either *transparent* (output contains argument bytes; overlap is sound) or *opaque-derived* (output is a function of argument values; must inherit the join of read-set labels). Unclassified tools must default to opaque-derived with full read-set inheritance, never to transparent. ## Decision Boundary The boundary between a safe and unsafe configuration is the tool registry's default classification and the planner's treatment of control-flow dependence. - **Unsafe:** tools default to "transparent"; propagation computed post-hoc by string search over outputs; control-flow branches on clean-looking derived values without taint checks. - **Safe:** every tool declares a read-set and a dependency class; opaque-derived outputs inherit the join of read-set labels; the planner treats any *branch condition* whose label is non-clean as a taint event, not just any *data argument* to a sink. The critical refinement: **control-flow taint matters as much as data-flow taint.** A boolean that gates a privileged action is a sink for taint purposes even if it never reaches a tool argument. The decision boundary is crossed the moment a derived value with inherited taint is used in a conditional that authorizes an effect. ## Operational Effect With dependency-closure labeling, the laundered boolean from the trace above carries `TAINT{untrusted}`, and the planner's `if contains: proceed` branch is flagged as control-flow-tainted. Policy then requires either human confirmation, a re-derivation of the predicate from a trusted source, or refusal. The injection is contained at the point of *decision*, not the point of *data transfer*—which is the only place it was ever reachable. The cost is precision: opaque-derived inheritance over-taints (a `count_matches` on a constant pattern over a tainted doc is tainted even if the count is benign). This is the correct trade—over-tainting degrades to extra confirmations, while under-tainting degrades to silent control-flow hijack. The registry classification must be audited whenever a tool's implementation changes its read-set, because a tool that newly reads a previously-unread argument becomes a new laundering channel without any code in the taint layer changing. ```python from dataclasses import dataclass, field from enum import Enum from typing import Any class TaintLaunderingError(RuntimeError): """Raised when a derived tool output would lose inherited taint.""" class ToolClass(Enum): TRANSPARENT = "transparent" # output contains argument bytes; overlap is sound OPAQUE_DERIVED = "opaque" # output is a function of argument values @dataclass(frozen=True) class Label: tainted: bool sources: frozenset = field(default_factory=frozenset) def join(self, other: "Label") -> "Label": return Label(self.tainted or other.tainted, self.sources | other.sources) CLEAN = Label(False) @dataclass class ToolSpec: name: str cls: ToolClass read_set: frozenset # argument names the implementation actually reads REGISTRY = { "string_contains": ToolSpec("string_contains", ToolClass.OPAQUE_DERIVED, frozenset({"text", "needle"})), "count_matches": ToolSpec("count_matches", ToolClass.OPAQUE_DERIVED, frozenset({"text", "pattern"})), "echo": ToolSpec("echo", ToolClass.TRANSPARENT, frozenset({"text"})), } def label_tool_output(spec: ToolSpec, arg_labels: dict, output: Any) -> Label: if spec.cls is ToolClass.TRANSPARENT: # overlap propagation is sound only for transparent tools return CLEAN.join(*arg_labels.values()) if arg_labels else CLEAN # OPAQUE_DERIVED: output is value-dependent on every read-set argument missing = spec.read_set - arg_labels.keys() if missing: raise TaintLaunderingError( f"tool {spec.name!r} reads {sorted(missing)} but no label supplied; " f"cannot compute dependency-closure label" ) result = CLEAN for name in spec.read_set: result = result.join(arg_labels[name]) return result def guard_control_flow(condition_label: Label, authorizes_effect: bool) -> None: """A tainted value used to gate a privileged effect is a control-flow taint sink.""" if authorizes_effect and condition_label.tainted: raise TaintLaunderingError( "control-flow taint: derived value with inherited taint gates a privileged " f"effect (sources={sorted(condition_label.sources)})" ) # --- reproduction of the observed failure --- untrusted = Label(True, frozenset({"email_body"})) spec = REGISTRY["string_contains"] cond_label = label_tool_output(spec, {"text": untrusted, "needle": CLEAN}, True) # cond_label.tainted is True under dependency-closure; overlap propagation would have said CLEAN. guard_control_flow(cond_label, authorizes_effect=True) # raises ```