# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-taint-propagation-failure-at-the-tool-call-gate-the-deferred-argument-laundering-boundary.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-taint-propagation-failure-at-the-tool-call-gate-the-deferred-argument-laundering-boundary.warrant.json # Markdown SHA-256: 15a7e29828ccac3207a163a95bd42e8b74871ec3bb2d84dea5e0822361dd9d2a # Code AST SHA-256: cf1bf0a28d12bde19eb6b883da9a086b0513db3719ec03328cc842a10e5ff8a9 # Verified Classes: TaintLaunderingError, Value, ToolReturn # 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 TRUSTED = "trusted" UNTRUSTED = "untrusted:retrieved" class TaintLaunderingError(RuntimeError): """Raised when a privileged call's argument provenance cannot be resolved to a fully trusted origin, or when a taint sink strips provenance.""" pass @dataclass class Value: span: str label: str origin: Optional[str] = None # id of source value, if derived resolved: bool = True @dataclass class ToolReturn: tool: str fields: dict input_origins: list = field(default_factory=list) def propagate_taint(ret: ToolReturn, inputs: list[Value]) -> ToolReturn: """Invariant: any tool whose input set intersects tainted values must produce tainted output. A tool return is trusted only if ALL inputs trusted.""" any_tainted = any(v.label != TRUSTED for v in inputs) if any_tainted: for k in ret.fields: ret.fields[k] = Value(span=ret.fields[k].span, label=UNTRUSTED, origin=ret.fields[k].origin, resolved=ret.fields[k].resolved) ret.input_origins = [v.origin for v in inputs] return ret def gate_privileged_call(arg: Value, tainted_spans: set) -> None: """Fail-closed gate. Admits only when provenance is fully resolved and trusted.""" if not arg.resolved: raise TaintLaunderingError( f"unresolved provenance for argument {arg.span!r}; failing closed") if arg.label != TRUSTED: raise TaintLaunderingError( f"argument {arg.span!r} carries taint label {arg.label!r}") # substring-overlap check: extraction must not launder for span in tainted_spans: if span and span in arg.span: raise TaintLaunderingError( f"argument {arg.span!r} contains tainted span {span!r} " f"despite clean label; laundering suspected") def send_email(to: Value, body: Value, tainted_spans: set) -> None: gate_privileged_call(to, tainted_spans) gate_privileged_call(body, tainted_spans) # ... perform send ...