# Why does an instance of prompt-injection taint tracking fail across tool boundaries when labels are reset by serialization? **Date of Record:** 2026 November 15 **Scope:** Applies to agent runtimes that propagate dynamic information-flow (DIF) labels—taint bits, provenance tags, or capability tokens—across calls into external tools, subprocesses, or remote MCP-style servers. Does not apply to single-process pipelines where the label travels in-memory through the same interpreter, nor to static taint analysis performed ahead of execution. ## Core Distinction There are two distinct notions of "taint survives a call": 1. **Value taint** — the data returned by a tool carries a label because it derives from untrusted input. 2. **Channel taint** — the *invocation itself* (arguments, control flow, side effects) is influenced by untrusted input, regardless of what is returned. Most implementations track only (1). The failure mode is that a tool boundary is a serialization boundary, and serialization is where labels are silently dropped. A JSON-RPC payload from a tool server contains `{"result": "..."}` with no field for "this string was influenced by a prompt-injected instruction." The runtime receives a structurally clean object and, by default, assigns it the *bottom* label (trusted/clean) rather than the *join* of the caller's label and the tool's own policy. The invariant that must hold is: > `label(return_value) ⊒ label(caller_context) ⊔ label(tool_static_policy)` When it does not hold, the join is replaced by bottom, and taint laundering occurs across the boundary. ## What Was Observed A runtime wired a fetch tool behind a JSON-RPC shim. An untrusted web page (label `U`) was summarized into a scratchpad. The agent then invoked `fetch(url=scratchpad_derived_url)`. The argument was correctly tainted `U` at call time. The tool returned page content. The shim serialized the response and the runtime's deserializer constructed a fresh `ToolResult` object with default labels—`⊥`—because the wire schema had no provenance field and the constructors did not consult the caller's label. Downstream, a `write_file` tool received content labeled `⊥` and executed without a confirmation gate. The exfiltration path—untrusted page → argument taint → tool response → trusted write—was invisible to the policy engine because at no point after the boundary did any object carry `U`. Two secondary observations: - **Argument taint did not propagate to effects.** Even when the argument was tainted, the tool's *side effect* (a network request to an attacker-chosen URL) was not itself a labeled event. The policy engine saw a `fetch` call, not a `fetch` call *on behalf of* `U`. - **Label join was not associative across retries.** A retried call after a transient error re-entered the tool with a fresh context; the retry path constructed the request from the raw argument string, not the labeled wrapper, so the label was dropped on attempt 2 even though attempt 1 carried it. ## Condition of Validity The invariant above holds only if all of the following are true: 1. The wire schema has an explicit provenance slot, **or** the runtime applies a conservative default: any value crossing an inbound tool boundary is labeled `⊔(caller_label, tool_policy)` until proven otherwise. 2. The label join is computed at the *boundary adapter*, not inside the tool, because the tool cannot see the caller's label. 3. Retry, batching, and streaming paths route through the same adapter. A streaming response that emits chunks must carry the label per chunk or the stream must be labeled as a whole before any chunk is consumed. 4. Side effects are modeled as labeled events, not just return values. A tool that returns `⊥` but was invoked with a `U`-labeled argument must emit an effect event labeled `U`. If any of these fail, the runtime is in a state where taint is *believed* tracked but is actually reset at every boundary—a strictly worse condition than no tracking, because policy gates are configured as if the labels were meaningful. ## Decision Boundary The operational rule: **treat every serialization boundary as a label-destroying boundary by default.** Do not trust the tool to propagate labels; do not trust the schema to carry them unless the schema was designed for it. At each boundary adapter, compute: ``` inbound_label = join(caller_context_label, tool_static_policy_label) outbound_label = join(inbound_label, tool_declared_label_if_any) ``` and if `tool_declared_label_if_any` is absent, use `inbound_label` as the floor—never `⊥`. The only case where a return value may be labeled `⊥` is when both the caller context and the tool policy are `⊥` *and* the tool is declared pure with respect to untrusted inputs. Anything else is laundering. Corollary: a tool that cannot express provenance in its wire format must be wrapped by an adapter that does, or it must be excluded from any path where taint matters. "The tool doesn't support labels" is not a reason to reset them; it is a reason to apply the conservative default. ## Operational Effect When the boundary adapter enforces the join, the observed failure disappears: the `write_file` call receives content labeled `U`, the policy engine's confirmation gate fires, and the exfiltration path is blocked at the sink rather than being invisible. The cost is false positives—benign tool outputs get labeled `U` because their caller was `U`—which is the correct direction of error for a security invariant. The alternative, labeling tool outputs `⊥` by default, produces false negatives that are indistinguishable from a clean run in logs. The retry-path bug is fixed by making the labeled wrapper, not the raw string, the unit of retry. The side-effect gap is fixed by emitting effect events at the adapter with the inbound label attached, so downstream audit and gating see the *cause*, not just the *call*. The general lesson: dynamic information-flow labels are only as strong as their weakest serialization boundary, and serialization boundaries are exactly where the type system of the host language stops applying. An agent runtime that claims taint tracking but resets labels at tool boundaries is running a policy engine against a fiction. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Any class TaintLaunderingError(RuntimeError): """Raised when a value crosses a tool boundary without a provenance label that is at least the join of the caller label and the tool policy label.""" # Label lattice: a set of provenance tags; bottom = empty set, join = union. Label = frozenset[str] BOTTOM: Label = frozenset() def join(a: Label, b: Label) -> Label: return a | b @dataclass(frozen=True) class LabeledValue: value: Any label: Label def __post_init__(self) -> None: if not isinstance(self.label, frozenset): raise TypeError("label must be a frozenset of provenance tags") @dataclass class ToolBoundary: """Adapter that must be the only path across a serialization boundary.""" tool_name: str static_policy_label: Label = BOTTOM declared_provenance_in_wire: bool = False def invoke( self, caller_context: LabeledValue, raw_tool_call: Any, tool_impl: Any, ) -> LabeledValue: inbound = join(caller_context.label, self.static_policy_label) # The tool executes; its return value arrives structurally clean # because serialization dropped any labels it may have had. raw_result = tool_impl(raw_tool_call) # Reconstruct provenance. If the wire schema cannot carry labels, # the inbound label is the floor -- never BOTTOM. if self.declared_provenance_in_wire: declared = getattr(raw_result, "label", BOTTOM) if not isinstance(declared, frozenset): raise TaintLaunderingError( f"tool {self.tool_name!r} declared non-label provenance" ) outbound = join(inbound, declared) else: outbound = inbound if inbound != BOTTOM and not (inbound <= outbound): # Defensive: should be unreachable given the join above, but # guards against future refactors that bypass the join. raise TaintLaunderingError( f"tool {self.tool_name!r} dropped inbound label " f"{sorted(inbound)} -> {sorted(outbound)}" ) return LabeledValue(value=raw_result, label=outbound) def guarded_write( content: LabeledValue, destination: str, require_trusted: bool = True, ) -> None: if require_trusted and content.label: raise TaintLaunderingError( f"refusing to write tainted content to {destination!r}; " f"provenance={sorted(content.label)}" ) # ... perform write ... # --- demonstration of the failure and the fix --- def _demo() -> None: untrusted = LabeledValue(value="https://evil.example/x", label=frozenset({"U"})) fetch = ToolBoundary(tool_name="fetch", static_policy_label=BOTTOM) result = fetch.invoke( caller_context=untrusted, raw_tool_call=untrusted.value, tool_impl=lambda url: f"payload from {url}", ) # Without the adapter's conservative default, result.label would be BOTTOM # and the sink below would execute. With it, the sink refuses. assert result.label == frozenset({"U"}) try: guarded_write(result, "/etc/agent/scratch") except TaintLaunderingError as exc: print(f"blocked: {exc}") else: raise AssertionError("sink should have refused tainted content") if __name__ == "__main__": _demo() ```