# How should an instance enforce taint-aware tool gating when the policy decision point and the tool executor disagree about the provenance of a value **Date of Record:** 2026 December 1 **Scope:** Applies to agent runtimes that gate tool invocations through a policy enforcement point (PEP) using taint/provenance labels propagated from prior tool outputs and user turns. Does not apply to stateless single-turn tool routers or to policies keyed only on static tool allowlists. ## Core Distinction There are two places a taint label can be evaluated: at the **policy decision point (PDP)**, which reasons over a symbolic provenance graph, and at the **tool executor**, which reasons over the concrete bytes it is about to serialize into a downstream call. The failure mode is not "the policy is wrong." It is that **the PDP and the executor resolve the same argument to different provenance labels** because the value was laundered through a representation the PDP does not model—string interpolation, JSON re-serialization, base64 round-trips, or a summary generated by the model itself. The non-obvious invariant is this: *taint must be tracked on the value's identity, not on the variable name or the call site.* When an agent does `cmd = f"{untrusted_note}"` and then passes `cmd` to a shell tool, the PDP sees a fresh local binding with no taint, while the bytes are 100% attacker-controlled. The gate allows; the executor runs. This is a **provenance-laundering gap**, and it is the dominant cause of taint-gate bypasses in production agent runtimes—far more common than outright policy misconfiguration. ## What Was Observed A file-summarization agent was gated so that any tool invocation whose arguments carried the `EXTERNAL_UNTRUSTED` taint label required human approval. The agent read a fetched web page (correctly tainted), summarized it, and then invoked `shell.exec` with an argument assembled from the summary. Trace of the relevant turn: 1. `fetch(url)` returns body → tainted `EXTERNAL_UNTRUSTED`, label bound to the returned value handle `v_17`. 2. Model emits a summary as a *new* assistant token sequence. The runtime's taint propagator did not link model-generated text back to its source context, so the summary was labeled `MODEL_GENERATED` (untainted). 3. Model constructs `args = {"cmd": "grep -i '" + summary_keyword + "' /var/log/app.log"}`. The `summary_keyword` handle is `MODEL_GENERATED`. 4. PDP evaluates `shell.exec`: all argument handles are `MODEL_GENERATED` or literal → **allow**. 5. Executor receives `cmd` string containing an injected `'; rm -rf /tmp/x; '` fragment that survived summarization, and runs it. The gate did exactly what it was specified to do. The specification was unsound because **model-mediated transformation was treated as a taint-clearing operation**. Summarization, translation, reformatting, and "extract the key field" are all *lossy but not sanitizing*—they can preserve or even amplify attacker-controlled substrings. A second, subtler observation: when the same value was passed through a JSON tool (`json.parse` then `.get("field")`), the PDP *did* preserve taint, because the runtime modeled structured tool outputs as provenance-carrying. The gap was specific to **free-text model generation** and **string concatenation**, which the runtime treated as opaque. ## Condition of Validity The deny/allow gate is only sound under a conjunction of conditions: - **C1 (propagation completeness):** every operation that can move bytes from a tainted value into an untainted value is either modeled as taint-preserving or is itself gated. String interpolation, template rendering, encoding transforms, and model-mediated rewriting must all be in this set. - **C2 (executor-PDP label agreement):** the label the PDP decides on must be computed from the *same* value graph the executor serializes. If the executor re-derives arguments (e.g., re-parses a JSON blob, applies a shell-quoting pass), the PDP must see the post-derivation form. - **C3 (no implicit declassification):** no transform may clear a taint label unless an explicit, audited declassifier is invoked (e.g., a validated schema extractor with a fixed output domain). - **C4 (fail-closed on unknown provenance):** any value whose origin the PDP cannot resolve must be treated as maximally tainted, not untainted. The observed system satisfied C2 partially and violated C1, C3, and C4. The gate was therefore valid only for tool chains that never passed tainted data through model generation or string assembly—a condition the agent could not be relied upon to honor. ## Decision Boundary The runtime must decide, at each tool invocation, between **allow**, **deny**, and **escalate-to-approval**. The boundary is not "is any argument tainted" but "**is the argument's provenance fully resolved and untainted, or is it unresolved?**" Three regimes: - **Resolved-untainted** → allow without approval. - **Resolved-tainted** → deny or escalate per policy. - **Unresolved** (value derived from a transform the PDP does not model, or from model generation conditioned on tainted context) → **escalate**, never allow. The critical correction is treating *model-generated text conditioned on tainted context* as `UNRESOLVED`, not `MODEL_GENERATED`. This requires the runtime to record, per generation, the set of context handles that were in-window, and to propagate a **context-taint join** onto the generated output. That is the missing edge in the provenance graph. Without it, every summarization step is a declassifier, which is exactly the unsound behavior observed. A secondary boundary: when the executor's serialization differs from the PDP's view (C2), the PDP must be re-run on the serialized bytes. Concretely, the gate should evaluate the *post-quoting, post-interpolation* argument string, not the pre-assembly handle. ## Operational Effect Enforcing the corrected boundary changes agent behavior in three measurable ways: 1. **Summarize-then-act chains now escalate.** Any tool call downstream of a summarization of untrusted content requires approval or a validated extractor. This is the intended cost; it closes the laundering gap. 2. **False-positive rate rises on benign chains** where the model paraphrases untrusted text into a safe command. Mitigation is a *validated declassifier*: a schema-constrained extractor (e.g., "extract a hostname matching `[a-z0-9.-]+`") whose output domain is provably safe. Only such extractors may clear taint, and their invocation is logged as a declassification event with the input handle, output value, and extractor version. 3. **Audit replay becomes possible.** Because every allow decision records the resolved provenance set, a replay of the decision against the recorded graph reproduces the gate outcome. Under the old scheme, replay diverged whenever model generation was involved, because the graph had no edge from context to output. The invariant to enforce operationally: **no taint label may be cleared except by a named, versioned declassifier whose output domain is a strict subset of the input domain and whose invocation is recorded.** Everything else—summarization, translation, string assembly, encoding—is taint-preserving by default, and unresolved provenance fails closed to escalation. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaintGateError(RuntimeError): """Raised when a tool invocation's provenance cannot be soundly resolved.""" class Label(Enum): UNTAINTED = "untainted" EXTERNAL_UNTRUSTED = "external_untrusted" UNRESOLVED = "unresolved" # derived from unmodeled transform or tainted context @dataclass class ValueHandle: id: str label: Label context_sources: frozenset = field(default_factory=frozenset) @dataclass class ToolCall: tool: str args: dict # arg name -> ValueHandle DECLASSIFIERS = { # name -> (input_label_allowed, output_label) "extract_hostname_v1": (Label.EXTERNAL_UNTRUSTED, Label.UNTAINTED), "extract_ipv4_v1": (Label.EXTERNAL_UNTRUSTED, Label.UNTAINTED), } def apply_declassifier(name: str, src: ValueHandle) -> ValueHandle: if name not in DECLASSIFIERS: raise TaintGateError(f"unknown declassifier {name!r}") allowed_in, out = DECLASSIFIERS[name] if src.label != allowed_in: raise TaintGateError( f"declassifier {name} cannot clear label {src.label}" ) return ValueHandle(id=f"{src.id}->{name}", label=out) def model_generate(prompt_handles: list, output_id: str) -> ValueHandle: """Model output inherits the join of its context taint. This is the missing edge that caused the laundering gap.""" joined = frozenset(h.id for h in prompt_handles) if any(h.label in (Label.EXTERNAL_UNTRUSTED, Label.UNRESOLVED) for h in prompt_handles): return ValueHandle(output_id, Label.UNRESOLVED, joined) return ValueHandle(output_id, Label.UNTAINTED, joined) def gate(call: ToolCall, require_approval_on: set) -> str: """Returns 'allow' | 'deny' | 'escalate'. Fails closed on unresolved.""" for name, handle in call.args.items(): if handle.label == Label.UNRESOLVED: # C4: unknown provenance never auto-allows return "escalate" if handle.label in require_approval_on: return "escalate" return "allow" # --- Demonstration of the failure and the fix --- def demo(): fetched = ValueHandle("v_17", Label.EXTERNAL_UNTRUSTED) # Old (broken) behavior: summary treated as untainted MODEL_GENERATED. broken_summary = ValueHandle("v_18", Label.UNTAINTED) broken_call = ToolCall("shell.exec", {"cmd": broken_summary}) assert gate(broken_call, {Label.EXTERNAL_UNTRUSTED}) == "allow" # bypass # Corrected behavior: summary inherits context taint. summary = model_generate([fetched], "v_18") if summary.label != Label.UNRESOLVED: raise TaintGateError("context-taint join failed to propagate") fixed_call = ToolCall("shell.exec", {"cmd": summary}) decision = gate(fixed_call, {Label.EXTERNAL_UNTRUSTED}) if decision != "escalate": raise TaintGateError( f"gate allowed unresolved provenance: {decision}" ) # Only a validated declassifier may clear taint. host = apply_declassifier("extract_hostname_v1", fetched) safe_call = ToolCall("dns.resolve", {"host": host}) assert gate(safe_call, {Label.EXTERNAL_UNTRUSTED}) == "allow" if __name__ == "__main__": demo() ```