# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-happens-when-an-instance-trusts-a-tainted-mcp-resource-read-label-laundering-across-the-resource-context-boundary.md # Remnant Warrant: https://corpusfetch.com/c/what-happens-when-an-instance-trusts-a-tainted-mcp-resource-read-label-laundering-across-the-resource-context-boundary.warrant.json # Markdown SHA-256: 2f44f8f5a044649952e288cf0d0408c371c541135355ccca8771f10c7fc57584 # Code AST SHA-256: c522bc8b68d979dc5a3ea6332b03832a841e3f9fdf3dbd5651ccd9155c712451 # Verified Classes: Taint, TaintLaunderingError, Segment # Defensive Guards: 4 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass, field from enum import IntEnum from typing import Optional class Taint(IntEnum): TRUSTED = 0 UNTRUSTED = 1 class TaintLaunderingError(RuntimeError): """Raised when a transform or authorization step would launder untrusted taint.""" @dataclass class Segment: text: str taint: Taint provenance: list[str] = field(default_factory=list) def read_resource(uri: str, body: str, server_trust: Taint, block_taint: Optional[Taint]) -> Segment: # Schema gap: if the server did not label the block, default to UNTRUSTED, # never to the server's own trust level. effective = block_taint if block_taint is not None else Taint.UNTRUSTED # Provenance-as-trust is the bug; we record both but taint wins. return Segment(text=body, taint=effective, provenance=[f"read:{uri}"]) def summarize(seg: Segment, summarizer_trust: Taint) -> Segment: # A summarizer is a trust-boundary crossing. Its output taint must be the # union of input taint and its own trust. If the host would mark the output # TRUSTED while input was UNTRUSTED, that is laundering. out_taint = Taint(max(seg.taint, summarizer_trust)) if seg.taint == Taint.UNTRUSTED and out_taint == Taint.TRUSTED: raise TaintLaunderingError( f"summarizer would launder taint for {seg.provenance}" ) return Segment(text=f"[summary]{seg.text[:64]}", taint=out_taint, provenance=seg.provenance + ["transform:summarize"]) def authorize_tool_call(tool: str, target_trust: Taint, justification: list[Segment]) -> None: # Authorization is keyed on segment taint, NOT target server provenance. if any(s.taint == Taint.UNTRUSTED for s in justification) and target_trust == Taint.TRUSTED: raise TaintLaunderingError( f"trusted-target call {tool!r} justified by untrusted segment: " f"{[s.provenance for s in justification if s.taint == Taint.UNTRUSTED]}" ) # Reproduce the observed incident: doc = read_resource( "files://uploads/note.md", "", server_trust=Taint.TRUSTED, # docs/files server is "trusted" infra block_taint=None, # server emitted no taint field ) assert doc.taint == Taint.UNTRUSTED # default-to-untrusted holds summary = summarize(doc, summarizer_trust=Taint.TRUSTED) assert summary.taint == Taint.UNTRUSTED # taint-monotonic # The call that exfiltrated in the wild: authorize_tool_call("docs://write", target_trust=Taint.TRUSTED, justification=[summary]) # ^ raises TaintLaunderingError, blocking the exfiltration path.