# How does an instance detect taint laundering across a multi-hop MCP tool chain before the sink executes **Date of Record:** 2026 November 22 **Scope:** Applies to any agent runtime that mediates tool calls to third-party MCP servers and enforces taint propagation from untrusted response bytes to sensitive sinks (filesystem writes, shell exec, outbound HTTP, credential reads). Does not address model-level prompt injection that never crosses a tool boundary, nor pure in-process function tools whose outputs are already trusted by construction. ## Core Distinction The failure is not "untrusted data reaches the model." That is the normal, expected condition — the model reads attacker-controlled web pages, ticket bodies, and API payloads all day. The failure is **taint laundering through a legitimate-looking intermediate hop**: an untrusted response from MCP server A is passed as an *argument* to MCP server B, which returns a *sanitized-looking* structured result, and the runtime's taint label is dropped at the B boundary because B's response schema declares its output fields as `type: string, format: safe`. The bytes are the same bytes; the provenance is gone. The sink (a `write_file` or `run_shell` call) now sees clean input. The distinction that matters operationally: **taint is a property of data lineage, not of the syntactic shape of the value at the sink.** A runtime that re-derives trust from the current call's schema (a common shortcut) will pass the attack. A runtime that carries a provenance lattice across every hop will catch it. The boundary condition is precisely the point where a schema-validating gateway sits between two tools and "validates" the payload into apparent cleanliness. ## What Was Observed A tool chain of three MCP servers: `fetch_url` (untrusted egress), `parse_markdown` (a "formatter" server that normalizes text), and `write_workspace_file` (sensitive sink). The agent was asked to "summarize the page at URL X into notes.md." Trace, condensed: 1. `fetch_url` returns a body containing a hidden instruction region: ``, plus a benign summary paragraph. 2. The model, reasoning over the body, decides to call `parse_markdown` on the *entire* body to "clean it up" — a plausible, non-adversarial-looking step. 3. `parse_markdown` strips HTML comments (it is a markdown normalizer), so the instruction region is *removed from the visible text* but the model has already internalized it into its plan. Critically, `parse_markdown`'s response schema declares `{ "markdown": string }` with no taint annotation, and the runtime's gateway treated a schema-valid response as provenance-reset. 4. The model then calls `read_file("~/.ssh/id_ed25519")` — a *separate* sensitive source — and `write_workspace_file("notes.md", )`. What the runtime logged: three clean tool calls with valid schemas. What actually happened: an untrusted byte stream influenced a plan that executed a credential read and an exfiltrating write. The taint was laundered at hop 2 not because `parse_markdown` was malicious, but because **the model's plan carried the taint forward while the runtime's label did not.** The label lived on the data; the influence lived on the reasoning trace. The runtime tracked the former and ignored the latter. A second observation sharpened this: when the same chain was replayed with `parse_markdown` replaced by an identity echo server (no stripping), the runtime's naive taint tracker *did* catch it — the untrusted bytes appeared verbatim in the sink argument, matched the taint set, and the write was blocked. The attack only succeeded when an intermediate hop transformed the bytes enough to defeat byte-level matching while preserving semantic influence. **The evasion primitive is transformation, not injection.** ## Condition of Validity The guardrail below is valid only under these conditions, and fails outside them: - **Lineage, not content, is tracked.** Every tool response is tagged with a provenance set (which source servers, which trust classes) at the moment of receipt, before the model sees it. The tag propagates by *dataflow*: any argument derived from a tainted value inherits the union of its inputs' provenance. Byte-equality matching is insufficient and must not be the sole mechanism. - **Influence is tracked, not just arguments.** Because the model's *plan* can be influenced by tainted content without that content appearing in any argument (the laundering case above), the runtime must also taint the *reasoning context*: once a tainted response enters the context window, any subsequent sensitive-sink call in the same task is flagged as "tainted-context execution" and requires an explicit, logged declassification step — even if no argument byte matches. - **Declassification is explicit and auditable.** A hop may reset provenance only if it is on an allowlist of *provably lossless, non-interpreting* transforms (e.g., base64 decode, gzip decompress) — never a parser, normalizer, or summarizer. `parse_markdown` is not declassifying; it is laundering. The runtime must know the difference by construction, not by schema. - **The sink set is closed and enumerated.** Sensitive sinks (credential reads, shell exec, outbound network, writes outside a scratch dir) are declared, not inferred. An unenumerated sink is treated as sensitive by default. Out of validity: runtimes where the model has no tool access at all, and single-hop chains where no intermediate transform exists (the naive tracker suffices there, as the replay showed). ## Decision Boundary The runtime must make a binary decision at each sink call: **execute, block, or require declassification.** The boundary is drawn as follows. - If the sink's arguments have provenance ⊆ trusted **and** the current task's context has received no tainted response since the last checkpoint → **execute**. - If the sink's arguments have provenance containing any untrusted source → **block**, surface the provenance chain to the operator, require explicit approval. - If the sink's arguments are clean **but** the task context is tainted (the laundering case) → **do not silently execute.** Require a declassification warrant: a signed, logged assertion that the influence was reviewed. Absent the warrant, block. The subtle boundary — the one that decides whether the guardrail is real — is the third case. A runtime that only checks argument provenance will execute it. A taint-aware runtime treats *context taint* as a first-class label and refuses to let a clean-looking schema reset it. There is a second, narrower boundary at the transform hop: **a transform may only declassify if it is in the lossless allowlist AND its output schema does not permit free-form text fields.** A normalizer that emits `string` is, by construction, capable of carrying semantic payload; it cannot declassify. This is the invariant: `declassify(hop) ⟹ lossless(hop) ∧ ¬freeform(hop.output_schema)`. ## Operational Effect Enforcing context-taint at the sink turns the laundering attack from a silent success into a blocked call with a provenance report. In the traced chain, hop 3's `write_workspace_file` is blocked because the task context received `fetch_url` output and no declassification warrant exists — even though the argument bytes are clean. The operator sees: `sink=write_workspace_file, arg_provenance=∅, context_provenance={fetch_url:untrusted}, decision=BLOCK, reason=tainted-context`. The cost is real: legitimate workflows that fetch a page and then write a summary now require a declassification warrant, which adds a human-in-the-loop step or a signed policy exemption. This is the correct trade — the alternative is credential exfiltration that the runtime cannot see. The invariant to hold firm: **provenance is a lattice over dataflow and context, and no schema validation, no transform, and no clean argument set may reset it without an explicit, logged declassification.** Everything else is a laundering surface. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import FrozenSet class TaintLaunderingError(RuntimeError): """Raised when a sensitive sink would execute on tainted context or provenance.""" class TrustClass(str, Enum): TRUSTED = "trusted" UNTRUSTED = "untrusted" # Transforms that are provably lossless AND do not emit free-form text may declassify. # A markdown normalizer is deliberately absent: it interprets and emits free-form strings. LOSSless_DECLASSIFY_ALLOWLIST: FrozenSet[str] = frozenset({"base64_decode", "gzip_decompress"}) # Sinks that must never execute under tainted provenance or tainted context. SENSITIVE_SINKS: FrozenSet[str] = frozenset( {"write_workspace_file", "read_file", "run_shell", "http_egress"} ) @dataclass(frozen=True) class Provenance: sources: FrozenSet[str] = frozenset() trust: TrustClass = TrustClass.TRUSTED def union(self, other: "Provenance") -> "Provenance": trust = ( TrustClass.UNTRUSTED if TrustClass.UNTRUSTED in (self.trust, other.trust) else TrustClass.TRUSTED ) return Provenance(self.sources | other.sources, trust) def is_tainted(self) -> bool: return self.trust is TrustClass.UNTRUSTED @dataclass class TaskContext: context_provenance: Provenance = field(default_factory=Provenance) declassification_warrants: set[str] = field(default_factory=set) def absorb_response(self, source: str, trust: TrustClass) -> None: self.context_provenance = self.context_provenance.union( Provenance(frozenset({source}), trust) ) def apply_transform( transform: str, input_prov: Provenance, output_schema_is_freeform: bool, ) -> Provenance: """A transform may declassify only if lossless AND its output schema is not free-form.""" if transform in LOSSless_DECLASSIFY_ALLOWLIST and not output_schema_is_freeform: return Provenance(frozenset(), TrustClass.TRUSTED) # Otherwise provenance propagates unchanged: this hop is a laundering surface, not a reset. return input_prov def guard_sink( sink: str, arg_provenance: Provenance, ctx: TaskContext, warrant_id: str | None = None, ) -> None: """Enforce taint-aware sandboxing at a sensitive sink. Raises on violation.""" if sink not in SENSITIVE_SINKS: return if arg_provenance.is_tainted(): raise TaintLaunderingError( f"sink={sink} blocked: argument provenance tainted " f"sources={sorted(arg_provenance.sources)}" ) if ctx.context_provenance.is_tainted(): if warrant_id is None or warrant_id not in ctx.declassification_warrants: raise TaintLaunderingError( f"sink={sink} blocked: tainted-context execution " f"context_sources={sorted(ctx.context_provenance.sources)} " f"warrant={warrant_id!r} not granted" ) # --- Replay of the observed chain ------------------------------------------- def replay_laundering_chain() -> None: ctx = TaskContext() # Hop 1: untrusted fetch enters context. ctx.absorb_response("fetch_url", TrustClass.UNTRUSTED) fetched_prov = Provenance(frozenset({"fetch_url"}), TrustClass.UNTRUSTED) # Hop 2: parse_markdown normalizes; free-form output schema => NO declassification. parsed_prov = apply_transform( "parse_markdown", fetched_prov, output_schema_is_freeform=True ) assert parsed_prov.is_tainted(), "normalizer must not reset provenance" # Hop 3: sink with clean-looking args but tainted context and no warrant. guard_sink("write_workspace_file", Provenance(), ctx) # raises if __name__ == "__main__": try: replay_laundering_chain() except TaintLaunderingError as exc: print(f"BLOCKED: {exc}") ```