# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-taint-laundering-through-tool-call-argument-reconstruction-in-indirect-prompt-injection-defense.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-taint-laundering-through-tool-call-argument-reconstruction-in-indirect-prompt-injection-defense.warrant.json # Markdown SHA-256: d07788c7f9b3502b030cc10237de4cda1ad96f5f69427ce3595105d91e69b4ee # Code AST SHA-256: 54799094385656d57d4fde3e8e00d4a71c71fcbe2826ac81a3ff40759bbc53c0 # Verified Classes: TaintLaunderingError # 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) class TaintLaunderingError(RuntimeError): """Raised when a tool argument reconstructs a tainted span under a transformation that the lexical gate failed to detect.""" def __init__(self, tool: str, field: str, decoder: str, score: float): self.tool = tool self.field = field self.decoder = decoder self.score = score super().__init__( f"taint laundering in {tool}.{field} via {decoder} (recoverability={score:.3f})" ) DECODERS = { "identity": lambda s: s, "strip_separators": lambda s: "".join(c for c in s if c.isalnum()), "base64": _try_b64, "hex": _try_hex, "url": _try_url, } def recoverability(arg: str, tainted_spans: list[str], threshold: float = 0.85) -> tuple[str, float]: """Return (decoder_name, score) for the decoder that best reconstructs a tainted span.""" best = ("identity", 0.0) for name, fn in DECODERS.items(): decoded = fn(arg) if decoded is None: continue for span in tainted_spans: score = _similarity(decoded, span) # e.g. normalized edit similarity if score > best[1]: best = (name, score) return best def gate_tool_call(tool: str, args: dict, tainted_spans: list[str]) -> None: schema = TOOL_SCHEMAS[tool] for field, value in args.items(): if not isinstance(value, str): continue if schema[field].constrained: continue # closed domain, reconstruction impossible decoder, score = recoverability(value, tainted_spans) if score >= 0.85: raise TaintLaunderingError(tool, field, decoder, score) if score >= 0.60: # ambiguous: refuse rather than pass a lexical-only check raise TaintLaunderingError(tool, field, f"{decoder}:ambiguous", score)