# How should an instance enforce taint-aware capability gating when a tool's output silently reclassifies its own caller's authority **Date of Record:** 2026 November 27 **Scope:** Applies to single-agent or multi-agent runtimes that gate tool invocation on the taint label of the *arguments* and the *provenance* of the *calling context*, where tool outputs can carry provenance that differs from the caller's. Does not cover pure input-sanitization filters or static allowlists that ignore provenance entirely. ## Core Distinction The failure is not "a tool returned untrusted data." It is that **taint propagation and capability authorization are evaluated at the wrong temporal boundary**: the gate checks the caller's taint *at call time*, but a tool's return value can carry a taint label that should retroactively constrain what the *same caller* may do *next* — and in most runtimes, the caller's own taint state is never updated by the callee's output. Authorization is computed from the pre-call context; the post-call context inherits a new provenance that the next gate never sees. Concretely: an agent holds capability `write:filesystem`. It calls `fetch_url`, which returns page content carrying provenance `UNTRUSTED_EXTERNAL`. That content is appended to the agent's working context. On the *next* turn, the agent invokes `write:filesystem` with a path derived from the fetched content. The gate sees a caller whose taint label is still `TRUSTED` (its own), arguments that are syntactically valid, and a capability that matches. It admits the call. But the *data flow* into the argument originated from `UNTRUSTED_EXTERNAL`. The taint was attached to the value, not to the caller, and the caller's authority was never downgraded. The invariant that is violated: **a capability gate must be evaluated against the join (least-upper-bound) of the caller's ambient taint and the taint of every data dependency in the call's arguments.** Runtimes that track only "caller taint" or only "argument taint" — but not their join — have a gap exactly where a trusted caller launders untrusted data into a privileged sink. ## What Was Observed A tool-using agent (capabilities: `read:web`, `write:filesystem`, `send:email`) was tasked with "summarize the vendor page and update our config." Trace: 1. Turn 1: `fetch_url("https://vendor.example/pricing")` → returns body; runtime tags the return value `provenance=EXTERNAL_UNTRUSTED`, confidence `0.9`. 2. Runtime appends body to context. Caller taint label remains `TRUSTED` (the agent's own identity was never modified — correct, identity ≠ data provenance). 3. Turn 2: agent emits `write:filesystem(path="/etc/app/config.yaml", content=)`. The `content` argument's data-dependency set includes the Turn-1 return value. The gate evaluated: - caller capability: `write:filesystem` ∈ granted set → pass - caller ambient taint: `TRUSTED` → pass - argument schema: valid YAML → pass - **argument provenance join: not computed** → the check did not exist. 4. Call admitted. Config overwritten with externally-controlled content. The non-obvious part: the runtime *did* have the provenance label, and *did* have the data-dependency edge (the argument was built by a templating step that recorded its inputs). The two facts lived in different subsystems — provenance in the content store, dependency edges in the planner's scratchpad — and the gate consulted neither jointly. This is the canonical taint-laundering gap: each component is individually sound, the composition is not. A second observation from the same incident: when the runtime was patched to compute the join, it over-blocked. It rejected `write:filesystem` even when the untrusted content had been *paraphrased* by the model into a summary with no verbatim dependency. The naive join treats "any token overlap with a tainted source" as taint, which is both unsound (paraphrase severs the dependency) and unusable (every web-grounded write blocks). The correct boundary is dependency-edge-based, not content-based. ## Condition of Validity The join-based gate is sound and usable only under these conditions: - **Provenance is attached to values, not to turns.** A label like `EXTERNAL_UNTRUSTED` must live on the data object returned by the tool and survive context assembly, truncation, and re-serialization. If the runtime re-renders context as a flat string (common in chat-template assembly), provenance must be carried out-of-band in a parallel structure keyed by span, or it is lost. - **Data-dependency edges are recorded at argument-construction time, not inferred post hoc.** The planner must log, for each emitted argument, the set of value-IDs it read. Inference from text similarity is not a valid substitute (see paraphrase failure above). - **The gate computes `join(caller_taint, ⋁ arg_dependency_taints)` and compares against the capability's required clearance.** A capability like `write:filesystem` requires clearance `TRUSTED`; a join of `EXTERNAL_UNTRUSTED` fails the comparison regardless of caller identity. - **Declassification is explicit and audited.** A summarizer or sanitizer tool may emit a value with reduced taint *only* if it is registered as a declassifier with a declared policy (e.g., "structured extraction, no free-text passthrough"). Implicit declassification — the model "just summarizing" — is the failure mode, not a mitigation. It does **not** apply when arguments are constructed entirely from constants or from `TRUSTED`-labeled sources with no external dependency; in that case the join equals caller taint and the check is a no-op (correctly). ## Decision Boundary The runtime must decide, per call, between **admit**, **admit-with-constraint** (e.g., write to a quarantine path, or require human confirmation), and **reject**. The boundary is set by the join, not by any single label: | caller taint | arg dependency join | required clearance | decision | |---|---|---|---| | TRUSTED | TRUSTED | TRUSTED | admit | | TRUSTED | EXTERNAL_UNTRUSTED | TRUSTED | **reject or constrain** ← the gap | | TRUSTED | EXTERNAL_UNTRUSTED | UNTRUSTED_OK | admit | | UNTRUSTED | TRUSTED | TRUSTED | reject (caller itself tainted) | | UNTRUSTED | UNTRUSTED | TRUSTED | reject | The critical cell is row 2: a trusted caller with untrusted data. Runtimes that gate on caller taint alone collapse rows 1 and 2 into "admit," which is the vulnerability. The decision boundary must be drawn on the join. Additionally, the boundary must be drawn on **dependency edges, not content** — a paraphrased summary with no recorded dependency edge to the external source is, by policy, `TRUSTED` *if and only if* the paraphrase happened inside a registered declassifier. Otherwise it is `UNTRUSTED` by default (fail-closed). ## Operational Effect When the join gate is in place, the observable effects are: - **Taint laundering via privileged sinks is blocked**, but the block is *specific*: only calls whose argument dependency set intersects an untrusted source and whose target capability exceeds `UNTRUSTED_OK` clearance are rejected. Web-grounded reads, summaries written to quarantine, and reads of untrusted data remain permitted. - **Fail-closed default on missing provenance.** If the runtime cannot resolve the dependency set for an argument (e.g., the planner crashed mid-construction and lost edges), the argument is treated as `UNTRUSTED`. This trades availability for soundness and must be monitored: a spike in "unknown provenance" rejections usually indicates a planner bug, not an attack. - **Declassifier registry becomes a security-critical surface.** Every tool that reduces taint must be registered with a declared policy and audited. An unregistered tool that returns `TRUSTED`-labeled output from `UNTRUSTED` input is a laundering channel and must be treated as a defect. - **Latency cost is bounded and local.** The join is computed from pre-recorded edges at argument-construction time; it adds no model calls and no re-inference. The cost is O(dependency-set size) per call, not O(context length). The residual risk that remains after the gate: a declassifier that is *registered but wrong* (e.g., a summarizer that faithfully copies a malicious instruction into its "structured" output). The gate cannot catch this — it trusts the declassifier's policy. That is why declassifier registration must be paired with output-shape constraints (structured fields only, no free-text passthrough), and why the declassifier set must be small and reviewed. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import FrozenSet class Taint(IntEnum): # Lower is more restrictive; join = min (least-upper-bound over clearance lattice) EXTERNAL_UNTRUSTED = 0 UNTRUSTED = 1 TRUSTED = 2 class TaintLaunderingError(RuntimeError): """Raised when a capability gate would admit a call whose argument dependency join is more restrictive than the target capability's required clearance (the trusted-caller / untrusted-data gap).""" @dataclass(frozen=True) class Value: id: str taint: Taint @dataclass(frozen=True) class Capability: name: str required_clearance: Taint @dataclass class Call: capability: Capability caller_taint: Taint arg_dependencies: FrozenSet[str] = field(default_factory=frozenset) def join_taint(taints) -> Taint: taints = list(taints) if not taints: return Taint.EXTERNAL_UNTRUSTED # fail-closed on unknown provenance return Taint(min(int(t) for t in taints)) def gate(call: Call, provenance: dict[str, Taint], declassifiers: FrozenSet[str]) -> str: # Resolve dependency taints; unknown value id => fail-closed dep_taints = [] for dep_id in call.arg_dependencies: if dep_id not in provenance: # Missing edge/label: cannot prove safe -> treat as untrusted dep_taints.append(Taint.EXTERNAL_UNTRUSTED) else: dep_taints.append(provenance[dep_id]) effective = join_taint([call.caller_taint, *dep_taints]) if effective < call.capability.required_clearance: raise TaintLaunderingError( f"capability {call.capability.name!r} requires clearance " f"{call.capability.required_clearance.name}, but " f"join(caller={call.caller_taint.name}, " f"args={[t.name for t in dep_taints]}) = {effective.name}; " f"refusing to launder untrusted data into a privileged sink" ) return "admit" # --- demonstration of the gap being closed --- prov = { "vendor_page": Taint.EXTERNAL_UNTRUSTED, "local_const": Taint.TRUSTED, } write = Capability("write:filesystem", required_clearance=Taint.TRUSTED) # Trusted caller, argument derived from external page -> must reject try: gate( Call(write, caller_taint=Taint.TRUSTED, arg_dependencies=frozenset({"vendor_page"})), prov, declassifiers=frozenset(), ) except TaintLaunderingError as e: print("BLOCKED:", e) # Trusted caller, argument from local constant -> admit print(gate( Call(write, caller_taint=Taint.TRUSTED, arg_dependencies=frozenset({"local_const"})), prov, declassifiers=frozenset(), )) ```