# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-quarantine-a-tainted-mcp-tool-result-before-it-crosses-a-trust-boundary-in-a-multi-hop-call-graph.md # Remnant Warrant: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-quarantine-a-tainted-mcp-tool-result-before-it-crosses-a-trust-boundary-in-a-multi-hop-call-graph.warrant.json # Markdown SHA-256: 06de17f27cd14bb4d7979d69915e8c47d0cdb1baf6bb777d98a55a7667aff64e # Code AST SHA-256: 3dbef32d415b48d7fe8734581240d4e8a9c452a6a4b18b31274a422ea749b7f5 # Verified Classes: TrustLevel, TaintLaunderingError, TaintedValue # Defensive Guards: 2 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 __future__ import annotations from dataclasses import dataclass, field from enum import IntEnum from typing import Iterable class TrustLevel(IntEnum): UNTRUSTED = 0 EXTERNAL = 1 INTERNAL = 2 TRUSTED = 3 class TaintLaunderingError(RuntimeError): """Raised when a node declares output taint below the join of its inputs. This is a provenance-integrity violation: the runtime can no longer reason about what the value is, regardless of whether the payload is actually malicious. """ @dataclass(frozen=True) class TaintedValue: payload: str taint: TrustLevel provenance: tuple[str, ...] = field(default_factory=tuple) def join_taint(inputs: Iterable[TrustLevel]) -> TrustLevel: """Taint lattice join: the least trusted input dominates.""" levels = list(inputs) if not levels: # No inputs: the node's own declared trust is the floor. return TrustLevel.TRUSTED return TrustLevel(min(int(l) for l in levels)) def relay_through_probabilistic_node( node_id: str, declared_output_taint: TrustLevel, inputs: list[TaintedValue], ) -> TaintedValue: """Model a probabilistic hop (summarizer, extractor, reformulator). The runtime computes the true taint as the join over *all* inputs, including the node's context. The node's self-declared taint is checked against that join; a mismatch is a laundering event. """ true_taint = join_taint(v.taint for v in inputs) if declared_output_taint > true_taint: raise TaintLaunderingError( f"node {node_id!r} declared taint {declared_output_taint.name} " f"but input join is {true_taint.name}; " f"provenance={[v.provenance for v in inputs]}" ) provenance = tuple(p for v in inputs for p in v.provenance) + (node_id,) return TaintedValue( payload="", taint=true_taint, provenance=provenance, ) def admit_to_instruction_channel( value: TaintedValue, channel_trust: TrustLevel, channel_name: str, ) -> TaintedValue: """Gate placement of a value into an instruction-bearing channel. Quarantine if the value's taint is below the channel's trust floor. """ if value.taint < channel_trust: raise TaintLaunderingError( f"refusing to place value with taint {value.taint.name} into " f"channel {channel_name!r} requiring {channel_trust.name}; " f"provenance={value.provenance}" ) return value def demo_failure_trace() -> None: fetched = TaintedValue( payload="page body with embedded directive", taint=TrustLevel.UNTRUSTED, provenance=("fetch-mcp",), ) # The summarizer is local and *claims* clean output. The runtime # computes the join and rejects the claim. admit_to_instruction_channel( relay_through_probabilistic_node( node_id="summarize-tool", declared_output_taint=TrustLevel.TRUSTED, # the bug inputs=[fetched], ), channel_trust=TrustLevel.TRUSTED, channel_name="orchestrator.planning_context", ) if __name__ == "__main__": try: demo_failure_trace() except TaintLaunderingError as exc: print(f"QUARANTINE: {exc}")