# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-taint-scope-escape-when-an-mcp-tool-re-derives-privileged-data-from-a-replayed-capability-warrant.md # Remnant Warrant: https://corpusfetch.com/c/how-does-an-instance-detect-taint-scope-escape-when-an-mcp-tool-re-derives-privileged-data-from-a-replayed-capability-warrant.warrant.json # Markdown SHA-256: 27548608e215d1c00f7616ffb930313a22a023199ab39e0f36111bc3f735889f # Code AST SHA-256: d995a06911a0eeb305fb5b584d3646c357aaaa865b41c73e57cba3b9b3a6676a # Verified Classes: TaintContinuityFault, TaintNode, Warrant, TaintLedger # Defensive Guards: 3 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 typing import Optional class TaintContinuityFault(RuntimeError): """Raised when a value's recomputed taint floor disagrees with the warrant's asserted floor.""" @dataclass class TaintNode: value_id: str label: str # e.g. "trusted", "untrusted:web" parents: list[str] = field(default_factory=list) @dataclass class Warrant: warrant_id: str scope: frozenset[str] asserted_taint_floor: str # claim by the minter — untrusted input to the check class TaintLedger: def __init__(self) -> None: self.nodes: dict[str, TaintNode] = {} def add(self, node: TaintNode) -> None: self.nodes[node.value_id] = node def recompute_floor(self, value_id: str) -> str: """Walk the derivation DAG; floor is the max taint over all ancestors.""" seen: set[str] = set() stack = [value_id] floor = "trusted" while stack: vid = stack.pop() if vid in seen: continue seen.add(vid) node = self.nodes.get(vid) if node is None: raise TaintContinuityFault(f"dangling taint reference: {vid}") if node.label != "trusted": floor = node.label stack.extend(node.parents) return floor def admit(warrant: Warrant, tool_required_scope: frozenset[str], value_id: str, ledger: TaintLedger) -> None: if not warrant.scope >= tool_required_scope: raise TaintContinuityFault( f"scope denied: {warrant.scope} does not cover {tool_required_scope}" ) recomputed = ledger.recompute_floor(value_id) if recomputed != warrant.asserted_taint_floor: raise TaintContinuityFault( f"taint-floor discontinuity on {warrant.warrant_id}: " f"warrant asserts {warrant.asserted_taint_floor!r} but DAG recomputes " f"{recomputed!r} for value {value_id}" )