# In what scenarios must an instance refuse a capability grant that taint analysis labels "clean" but whose provenance chain crosses an untrusted sink **Date of Record:** 2026 November 16 **Scope:** Applies to runtime taint-aware tool-gating systems where an agent's capability grant is evaluated against a data-flow taint lattice at the moment of tool invocation. Does not apply to static capability manifests resolved at session start, nor to systems where tool arguments are fully re-validated by an independent trust boundary downstream of the agent. ## Core Distinction The failure mode is not "tainted data reaches a privileged tool." That case is well-understood: the taint label propagates, the gate blocks, the agent gets a denial. The non-obvious boundary is the *label-clearing* operation. Taint engines clear a label when a value passes through a sanitizer, a schema validator, or a type coercion that the policy author believes produces a canonical, trusted form. The invariant that is silently violated: **a value can be label-clean at the point of grant evaluation while its provenance chain still crosses an untrusted sink that the sanitizer did not actually traverse.** Concretely, taint is a *forward* property (what flowed into this value), while grant evaluation is often a *point-in-time* property (what does this value look like now). When a sanitizer is registered for a type but the actual coercion path takes a shortcut — deserialization that reconstructs an object without invoking the sanitizer, a cache hit that returns a pre-sanitization object, an identity-preserving `dict` merge that copies a field from an unsanitized sibling — the label is cleared without the sanitization having occurred. The gate sees "clean" and grants. The provenance chain, if walked, would show the untrusted sink. ## What Was Observed In a multi-tool agent runtime, a file-write capability was gated on the taint label of the destination path. A path assembled from a retrieved document (untrusted) was passed through a `normalize_path()` sanitizer that cleared the `UNTRUSTED_SOURCE` label. Under load, the sanitizer's LRU cache returned a previously-normalized `Path` object for an equal-but-distinct string. The cache key was the raw string; the cached value was the normalized object. Because Python's `Path` equality and string equality diverge on trailing separators and `.` segments, a path like `./data/../etc/` hashed to the same cache slot as `etc/` and received the cached, label-cleared object. The grant evaluator saw a clean label and authorized a write outside the intended root. The taint was correct at every individual step; the *clearing* was incorrect because the cache decoupled the label-clearing event from the sanitization event. The second observation was structural: the provenance graph recorded the sanitizer as a node but did not record *which invocation* of the sanitizer cleared the label. Two invocations of `normalize_path()` — one that actually ran the sanitizer, one that hit cache — were indistinguishable in the audit trail. The gate had no way to ask "was this label cleared by a real sanitizer execution or by a cache shortcut?" ## Condition of Validity The refusal rule below is valid only when all of the following hold: 1. The taint engine supports label-clearing operations that are *distinct* from the sanitizer's actual execution (caches, memoization, identity-preserving merges, deserialization fast paths). 2. The capability grant is evaluated against the current label rather than against a re-walked provenance chain that re-executes or re-verifies each clearing node. 3. The untrusted sink is reachable from the value's origin without traversing a *verified* sanitizer execution — i.e., there exists at least one clearing event whose backing execution cannot be confirmed. When the runtime re-walks provenance and re-verifies each clearing node's execution record, the rule is unnecessary: the re-walk catches the cache shortcut directly. When all clearing operations are pure functions with no caching or identity aliasing, the rule is vacuous. ## Decision Boundary The gate must **refuse** the grant when the label is clean but the provenance chain contains a clearing node whose execution record is absent, ambiguous, or aliased to a different input than the one being evaluated. It must **grant** when every clearing node on the chain has a verifiable execution record keyed to the exact value identity being evaluated. The boundary is not "is the value tainted" — it is "is the *clearing* trustworthy." A clean label with an unverifiable clearing event is strictly more dangerous than a tainted label, because a tainted label triggers the standard denial path while a clean-but-unverified label passes silently. The correct default is to treat unverifiable clearing as equivalent to taint for gating purposes, and to emit a distinct audit event so the operator can distinguish "blocked because tainted" from "blocked because clearing could not be verified." ## Operational Effect Agents that implement this rule stop granting capabilities on cache-hit-cleared values and begin surfacing `ClearingUnverifiable` denials. The observable effect is a short-lived spike in denials immediately after deployment (previously-silent grants now block), followed by a steady state in which the denial rate reflects actual cache-shortcut frequency. The audit trail gains a new event class that lets operators locate sanitizers whose caching is unsound. The cost is that legitimate cache hits on genuinely-sanitized values now require an execution record; systems that cannot produce one must disable caching on sanitizers used in grant paths or accept the denials. ```python from dataclasses import dataclass from typing import Optional class ClearingUnverifiableError(RuntimeError): """Raised when a label-clearing event cannot be tied to a real sanitizer execution.""" pass @dataclass(frozen=True) class ClearingRecord: value_identity: str sanitizer_name: str executed: bool input_identity: Optional[str] def evaluate_grant( value_identity: str, label_is_clean: bool, clearing_chain: list[ClearingRecord], ) -> bool: """ Return True if the capability grant should be authorized. A clean label is necessary but not sufficient: every clearing node on the provenance chain must have a verifiable execution record keyed to the exact value identity being evaluated. Cache hits, identity-preserving merges, and deserialization fast paths produce records with executed=False or with an input_identity that does not match the value being evaluated. """ if not label_is_clean: # Standard taint path: deny, but this is not the boundary failure. return False for record in clearing_chain: if not record.executed: raise ClearingUnverifiableError( f"clearing node {record.sanitizer_name!r} for value " f"{value_identity!r} has no execution record (cache shortcut?)" ) if record.input_identity != value_identity: raise ClearingUnverifiableError( f"clearing node {record.sanitizer_name!r} cleared a different " f"input ({record.input_identity!r}) than the value being " f"evaluated ({value_identity!r}); label clearing is aliased" ) return True # Example: a cache-hit-cleared path must be refused even though its label is clean. try: evaluate_grant( value_identity="./data/../etc/", label_is_clean=True, clearing_chain=[ ClearingRecord( value_identity="./data/../etc/", sanitizer_name="normalize_path", executed=False, # cache hit, sanitizer never ran input_identity="etc/", # aliased to a different input ) ], ) except ClearingUnverifiableError as exc: print(f"grant refused: {exc}") ```