# Which invariants prevent taint laundering through nested tool-call authority in agentic RPC chains **Date of Record:** 2026 November 25 **Scope:** Applies to agents that execute tool calls via an RPC/transport layer (MCP-style servers, A2A handoffs, or internal tool brokers) where a single agent instance both (a) ingests untrusted content into its context and (b) holds authority to issue state-mutating tool calls. Does not apply to pure read-only agents, nor to systems where untrusted content and mutating authority are physically separated into distinct processes with no shared credential. ## Core Distinction The confused-deputy exploit here is not "the agent followed an injected instruction." It is subtler: **the agent laundered taint by re-labeling an untrusted value as a trusted one across an RPC boundary.** A taint-tracking sandbox correctly marks tool *outputs* derived from untrusted input as tainted. The failure occurs when a *nested* tool call consumes that tainted value as an *argument* and the receiving tool — which only sees its own argument list, not the provenance graph — treats the argument as first-party data and emits a fresh, untainted result. Taint is dropped at every RPC frame boundary because the wire schema carries *values*, not *provenance*. The invariant that must hold is: **taint is monotone across the call graph** — a call whose transitive argument set contains any tainted node must itself produce tainted output and must be denied mutating authority. The non-obvious part is that the laundering happens *legitimately*: no single tool misbehaves, and each frame's local policy check passes. ## What Was Observed A three-hop chain: `planner` agent → `fetch_and_summarize` tool → `write_record` tool. The planner read an external document (untrusted, taint=α), extracted a field, and passed it to `fetch_and_summarize`. That tool internally called `write_record` with the extracted field. The sandbox tagged the *planner's* context as tainted and blocked the planner from calling `write_record` directly. But `fetch_and_summarize` was registered as a *trusted* tool (it had passed a static audit), so its outbound call to `write_record` inherited the tool's trust level, not the argument's taint level. The injected field — a record ID plus a payload — was written. The trace: 1. `planner` receives `doc` with taint α. Sandbox sets `ctx.taint = {α}`. 2. `planner` calls `fetch_and_summarize(args={field: v})` where `v` derives from α. The broker checks: is `planner` allowed to call this tool? Yes. Does it forward taint? **No** — the wire schema on `fetch_and_summarize`'s request is `{field: string}`, no provenance slot. 3. `fetch_and_summarize` executes in its own sandbox frame with `ctx.taint = {}` (fresh). It calls `write_record(args={id: v.id, body: v.body})`. Its policy: `write_record` allowed, tool is trusted. Passes. 4. `write_record` commits. Taint never propagated past frame 2. The tell in the logs: the *same* value `v` appears as an argument in frame 2 (where the planner's taint was known) and frame 3 (where it was absent), but no identifier links them. Provenance was structurally unrepresentable at the boundary. ## Condition of Validity The exploit requires all of the following to co-occur; remove any one and the chain breaks: - **Nested call depth ≥ 2** where an intermediate tool is statically trusted. Single-hop calls are safe because the planner's own taint set is checked at the one boundary. - **Argument-shaped taint transfer.** The tainted value must flow as a *tool argument* into the next frame, not merely influence the agent's prose. Free-text influence that never becomes a structured argument does not launder. - **Taint reset at frame entry.** The receiving tool's sandbox initializes a fresh provenance context rather than inheriting the caller's. This is the default in most brokers because frames are treated as process-isolated. - **No capability-warrant binding.** The mutating tool authorizes on *caller identity* (the trusted tool), not on *argument provenance*. If `write_record` required a warrant scoped to the data's origin, the laundered argument would fail the warrant check. The invariant is only violated when trust is attached to the *caller* rather than to the *data lineage*. Static tool trust is a caller-identity property; taint is a data-lineage property. Confusing the two is the defect. ## Decision Boundary The boundary is: **propagate taint through the argument graph, not the caller graph.** Concretely, the broker must, at every RPC frame, compute the frame's input taint as the union of (caller's context taint) ∪ (taint of every argument value, resolved through the provenance store). A mutating tool call is admitted only if the resulting union is empty *or* the tool holds a warrant explicitly scoped to that taint origin. Two operational decisions follow: - **Trusted-tool exemption must be scoped, not global.** A tool marked trusted may *originate* untainted data, but it must not *strip* taint from arguments it received. Trust governs what a tool produces ex nihilo; it must never govern what it forwards. - **Provenance must survive serialization.** The wire schema needs an opaque provenance token per value (a content-addressed hash chained to the originating tainted node), and the receiving frame must reconstruct taint from those tokens before policy evaluation. Without a token, the frame cannot distinguish a first-party string from a laundered one. The guardrail is asymmetric: fail *closed* on missing provenance. An argument with no provenance token is treated as maximally tainted, because absence of lineage is indistinguishable from stripped lineage. ## Operational Effect Enforcing monotone taint propagation converts the confused-deputy chain from a silent write into a bounded denial. The planner's tainted value now arrives at `write_record` with its α token intact; `write_record`'s policy sees a non-empty taint union and, lacking an α-scoped warrant, raises. The cost is false positives on legitimate forwarding of tainted-but-authorized data, which is why the warrant mechanism exists: an operator can mint a narrowly scoped warrant (`write_record` may accept α-tainted `body` fields up to N bytes) rather than disabling propagation wholesale. The residual risk is provenance-token forgery by a compromised intermediate tool. Mitigate by having the broker — not the tool — stamp provenance tokens at the frame boundary, so a tool cannot mint a clean token for a value it received dirty. The broker is the only component that sees both the caller's taint set and the argument values, making it the sole sound place to enforce the invariant. ```python from dataclasses import dataclass, field from typing import Optional class TaintLaunderingError(RuntimeError): """Raised when a mutating call's transitive argument taint is non-empty and no warrant is scoped to the offending taint origin.""" pass @dataclass(frozen=True) class Provenance: origin: str # e.g. "untrusted:doc-42" token: str # broker-stamped content hash, unforgeable by tools @dataclass class Frame: caller_taint: frozenset[str] = frozenset() args: dict = field(default_factory=dict) def resolve_arg_taint(args: dict, provenance_store: dict) -> frozenset[str]: """Reconstruct taint from per-value provenance tokens. A value with no token is treated as maximally tainted (fail closed).""" taint: set[str] = set() for value in args.values(): token = getattr(value, "provenance_token", None) if token is None: taint.add("unattributed") # missing lineage == suspect continue prov: Optional[Provenance] = provenance_store.get(token) if prov is None: taint.add("unattributed") else: taint.add(prov.origin) return frozenset(taint) def admit_mutating_call( frame: Frame, provenance_store: dict, warrant_origins: frozenset[str], ) -> None: """Invariant: taint is monotone across the call graph. Union of caller taint and argument taint must be covered by a warrant.""" effective_taint = frame.caller_taint | resolve_arg_taint( frame.args, provenance_store ) uncovered = effective_taint - warrant_origins if uncovered: raise TaintLaunderingError( f"mutating call blocked: un-warranted taint {sorted(uncovered)} " f"reached frame via nested RPC; provenance token missing or " f"unstripped" ) # admitted: caller may proceed to commit # --- reproduction of the observed exploit, now bounded --- store = { "tok-abc": Provenance(origin="untrusted:doc-42", token="tok-abc"), } # planner's frame: caller taint known, arg carries its token planner_args = {"field": type("V", (), {"provenance_token": "tok-abc"})()} planner_frame = Frame(caller_taint=frozenset({"untrusted:doc-42"}), args=planner_args) # fetch_and_summarize's nested frame: caller_taint reset to empty (the bug), # but the argument token survives serialization and is re-resolved here. nested_frame = Frame(caller_taint=frozenset(), args=planner_args) admit_mutating_call(nested_frame, store, warrant_origins=frozenset()) # -> raises TaintLaunderingError: "untrusted:doc-42" is un-warranted, # proving the laundering path is closed even when caller trust is reset. ```