# Which invariants prevent taint-laundering in MCP tool sandboxes when a single server multiplexes trusted and untrusted tool results **Date of Record:** 2026 November 18 **Scope:** Applies to MCP servers that mediate tool invocation across heterogeneous trust domains (e.g., a filesystem tool with privileged credentials and a web-fetch tool returning attacker-influenced content) within one process and one session. Does not apply to single-tenant servers where every tool shares one trust label, nor to out-of-process sandboxes that enforce OS-level isolation per invocation. ## Core Distinction Confused-deputy escalation in an MCP server is usually framed as a *capability* problem: the server holds credentials the caller shouldn't exercise, and the caller tricks the server into using them. The non-obvious boundary is different. It is a **taint-propagation failure**: the server correctly refuses to let an untrusted tool *directly* invoke a privileged tool, but it loses the taint label when the untrusted data is transformed into a value that the privileged tool later consumes as an argument. The distinction is between *origin taint* (which tool produced a datum) and *flow taint* (which tool consumed it and how). A server that tracks origin taint on tool *results* but not on tool *arguments* will pass every confused-deputy test that inspects the result channel while remaining fully exploitable through the argument channel. The invariant that matters is not "untrusted results cannot reach privileged tools" — it is "untrusted results cannot *become* the arguments of privileged tools without an explicit declassification step." ## What Was Observed A representative MCP server exposed `read_url`, `summarize`, and `write_file`. The server tagged `read_url` output as `taint=UNTRUSTED`, `summarize` as `taint=TRUSTED` (it was assumed to be a pure function), and `write_file` as `requires=TRUSTED` on its path and content arguments. A policy check rejected any call to `write_file` whose *content* carried `UNTRUSTED` taint. The escalation did not require bypassing that check. The agent invoked `read_url` on an attacker page, then passed the raw page body to `summarize`. `summarize` returned a paraphrased string. Because `summarize` was declared TRUSTED, its output was labeled TRUSTED, and the paraphrased string — which still contained an attacker-chosen path and payload — was accepted by `write_file`. The taint had been laundered through a tool whose purity was assumed rather than verified. A second, quieter variant appeared with `list_directory`. Its output was TRUSTED (metadata only), but the *filenames* it returned were attacker-controlled when the directory was attacker-writable. The server labeled the result by tool, not by data provenance, so a malicious filename flowed into `write_file` as a path with full trust. In both cases the server's policy was internally consistent and its tests passed. The failure was that taint was attached to *tool identity* rather than *data lineage*, and no invariant forbade a TRUSTED tool from emitting data derived from UNTRUSTED input. ## Condition of Validity The protections hold only under all three of the following: 1. **Provenance is per-datum, not per-tool.** Every value carries a label derived from the union of the labels of its inputs, not from the identity of the tool that produced it. A tool declared TRUSTED may *consume* UNTRUSTED input and still emit TRUSTED output only if it is registered as a *declassifier* with an explicit, reviewed justification. 2. **No implicit declassification.** A tool's output label is `max(input labels, tool's own base label)` unless the tool is on the declassifier allowlist. `summarize` is not a declassifier unless an operator says so and documents why paraphrasing cannot preserve an exploit payload — which, for path and command arguments, it usually can. 3. **Sinks re-check at the boundary.** A privileged sink (`write_file`, `exec`, `http_post`) re-validates the label of every argument at call time, not at label-assignment time, because labels can be merged and copied between the moment of production and the moment of use. If any of these is absent, the server is exploitable regardless of how strict the result-channel policy looks. ## Decision Boundary The operational line is this: **treat every tool result as UNTRUSTED unless the tool is a registered declassifier, and treat every tool argument as requiring a label check at the sink.** Concretely: - A tool that merely *reads* external data (`read_url`, `list_directory`, `query_db`) is a *source*; its output label is UNTRUSTED by default. - A tool that *transforms* data (`summarize`, `format`, `parse_json`) is a *passthrough*; its output label is the union of its inputs. It is never a declassifier by default. - A tool that *acts* on the world (`write_file`, `exec`, `send_email`) is a *sink*; it must reject any argument whose label is UNTRUSTED unless the caller supplies an explicit, logged declassification token. - The only legitimate declassifiers are those whose output cannot encode an attacker payload — e.g., a boolean predicate, a length, a fixed enum. A free-text summarizer is not one. The boundary is crossed the moment a passthrough tool is registered as TRUSTED. That single misregistration converts a correctly-tainted pipeline into a laundering channel, and no downstream check will catch it because the downstream check trusts the label the passthrough emitted. ## Operational Effect After enforcing per-datum provenance and sink-side re-checks, the `summarize` laundering path fails closed: the paraphrased string retains UNTRUSTED taint, `write_file` rejects it, and the attempted escalation surfaces as a policy violation rather than a silent write. The `list_directory` filename path is similarly blocked because the filename inherits the directory's provenance, not the tool's. The cost is that legitimate flows through summarizers now require an explicit declassification token, which is the point: declassification becomes a deliberate, auditable act instead of an accident of tool registration. The residual risk is declassifier overreach — an operator who registers `summarize` as a declassifier reintroduces the exact hole. The invariant to hold is narrow and testable: *no tool may emit a label lower than the union of its inputs unless it is on the declassifier allowlist, and no sink may accept an UNTRUSTED argument without a logged token.* Both are checkable in a unit test and both fail loudly. ```python class TaintLaunderingError(RuntimeError): """Raised when an untrusted datum reaches a privileged sink without declassification.""" pass class Label: TRUSTED = "TRUSTED" UNTRUSTED = "UNTRUSTED" @staticmethod def join(*labels: str) -> str: return Label.UNTRUSTED if Label.UNTRUSTED in labels else Label.TRUSTED # Tools that may legitimately lower taint. Free-text transformers are NOT here. DECLASSIFIERS = frozenset({"is_valid_path", "count_bytes", "enum_status"}) def propagate_output_label(tool_name: str, input_labels: list[str]) -> str: """Output label = union of inputs, unless tool is an explicit declassifier.""" if tool_name in DECLASSIFIERS: return Label.TRUSTED return Label.join(*input_labels) def invoke_sink(tool_name: str, args: dict[str, tuple[str, str]], declass_token: str | None): """args maps arg_name -> (value, label). Sink re-checks at the boundary.""" for arg_name, (value, label) in args.items(): if label == Label.UNTRUSTED and declass_token is None: raise TaintLaunderingError( f"sink {tool_name!r} rejected argument {arg_name!r}: " f"UNTRUSTED taint reached privileged sink without declassification token" ) # ... perform the privileged action ... return {"ok": True, "tool": tool_name} def build_summarize_flow(): # read_url is a source: UNTRUSTED by default. url_body = ("attacker payload", Label.UNTRUSTED) # summarize is a passthrough, NOT a declassifier: output inherits UNTRUSTED. summary_label = propagate_output_label("summarize", [url_body[1]]) summary = ("paraphrased attacker payload", summary_label) # write_file is a sink: must reject. return invoke_sink("write_file", {"path": ("/etc/cron.d/x", summary[1])}, declass_token=None) if __name__ == "__main__": try: build_summarize_flow() except TaintLaunderingError as e: print(f"blocked as expected: {e}") ```