# Under what conditions must an instance deny a tool invocation that is authorized by its static capability grant but violates the runtime policy's effective scope **Date of Record:** 2026 November 14 **Scope:** Applies to agent runtimes that enforce least-privilege capability scoping at the invocation boundary, where a static grant (issued at session start or delegated) and a runtime policy (evaluated per call against live context) are both consulted. Does not apply to systems with a single, statically evaluated authorization decision, nor to post-hoc audit-only logging without enforcement. ## Core Distinction A static capability grant answers *"may this principal ever exercise this verb on this resource class?"* A runtime policy answers *"may this specific invocation, with these arguments, at this moment, from this context, proceed?"* These are different predicates over different domains, and the failure mode lives in the gap between them. The non-obvious invariant: **a static grant is a precondition, never a sufficient condition.** An invocation is permitted only when *both* the grant admits the (principal, verb, resource-class) triple *and* the runtime policy admits the fully-resolved invocation. Runtimes that treat "grant present" as terminal authorization — short-circuiting policy evaluation for efficiency — will permit invocations that the runtime policy was specifically designed to block. The subtle part is that the grant and the policy often *appear* to overlap. A grant for `fs.write` on `/workspace/**` and a policy that says "no writes outside `/workspace/scratch/`" look redundant until you realize the grant's glob and the policy's scope are evaluated against different path resolutions: the grant against the *declared* argument, the policy against the *canonicalized* argument after symlink resolution, `..` collapsing, and mount-point normalization. A path like `/workspace/scratch/../../../etc/config` satisfies the grant's glob against the raw string but canonicalizes outside the policy's scope. This is the canonical boundary failure. ## What Was Observed In a deployment enforcing per-call policy over a tool-invocation gateway, an agent held a session grant for `net.fetch` scoped to `*.internal.example`. The runtime policy additionally constrained outbound fetches to hosts resolvable to RFC1918 addresses and to ports in an allowlist. During a routine task the agent issued a fetch to `metadata.internal.example:80`. The grant admitted the host (matches `*.internal.example`), so a fast-path check returned "authorized" and the call proceeded — bypassing the policy's address-class check. The hostname resolved to the cloud metadata endpoint `169.254.169.254`, a link-local address outside RFC1918 and explicitly denied by policy. The static grant's glob had no knowledge of DNS resolution; the policy did, but was never consulted because the grant check short-circuited it. The invocation succeeded and returned instance credentials. A second, quieter occurrence: a `db.query` grant scoped to the `analytics` schema. The policy restricted queries to tables tagged `pii=false`. A query against `analytics.users` — an unqualified table name that resolved, via the connection's `search_path`, to a PII-tagged table in a different schema — passed the grant check (schema matched `analytics` in the declared argument) but would have been denied by the policy had it been evaluated against the resolved table identity. It was not evaluated, because the grant matched. In both cases the grant was *necessary and correctly issued*. The defect was treating it as sufficient. ## Condition of Validity The invariant "grant admits ⇒ invocation permitted" holds only under the following conditions, all of which must be simultaneously true: 1. **Argument domain closure.** The grant's resource selector ranges over exactly the same value domain as the policy's. If the policy evaluates canonicalized/resolved values and the grant evaluates raw declared values, the domains differ and the fast-path is unsound. This fails for paths (symlinks, `..`), hostnames (DNS, CNAME chains, search domains), SQL identifiers (search_path, synonyms), and URLs (redirects, userinfo confusion). 2. **Context independence.** The policy consults only static, grant-time-fixed context. If the policy depends on runtime context (caller identity derived from token, current time, rate state, prior-call history, resolved address), the grant cannot encode it and short-circuiting discards it. 3. **Monotonic restriction.** The policy is a *restriction* of the grant, never an *extension*. If any valid policy decision could permit something the grant forbids, the grant is not even a sound precondition — a separate defect. The common case is restriction, which is what makes the fast-path tempting. 4. **No time-of-check/time-of-use gap.** The grant's evaluation and the invocation's execution are atomic with respect to the resource's state. DNS rebinding, symlink swaps, and schema migrations between grant-check and execution violate this even when conditions 1–3 hold. When any of these is false — and in real deployments at least condition 1 is routinely false — the grant is a precondition only, and the policy must be evaluated unconditionally. ## Decision Boundary The decision procedure at the invocation boundary is: ``` resolve(invocation) -> canonical_invocation if not grant.admits(principal, verb, resource_class(canonical_invocation)): DENY (grant is necessary) decision = policy.evaluate(canonical_invocation, runtime_context) if decision is not PERMIT: DENY (policy is necessary; never skipped when grant admits) EXECUTE with canonical_invocation ``` The critical ordering constraint: **canonicalize before both checks, and never evaluate the policy against a less-resolved value than the one executed.** If the grant is evaluated against the raw argument for performance, the policy must still be evaluated against the canonical argument, and execution must use the canonical argument. Evaluating the policy against the raw argument and executing the canonical one reintroduces the gap. The boundary is *not* "deny when grant and policy disagree" — that framing invites treating the grant as authoritative on conflict. The boundary is: both must permit, evaluated over the same canonical domain, with the policy consulted unconditionally whenever the grant admits. A grant that admits and a policy that denies yields DENY; there is no tie-breaking toward the grant. ## Operational Effect The observable effect of getting this wrong is a class of privilege-escalation that static analysis of grants will never surface, because every grant in the audit log is legitimate. Post-incident review sees "the agent used a capability it was granted" and closes the ticket. The escalation is invisible precisely because the static layer is correct. The correct implementation costs one canonicalization pass and one policy evaluation per invocation, even on the grant-hit path. The optimization that removes the policy evaluation on grant hit is the defect — it trades a per-call cost for an unbounded authorization hole whose exploitation requires only that an attacker influence an argument that canonicalizes differently than it declares. Two defensive practices follow. First, **canonicalize once, at the boundary, and thread the canonical value through grant-check, policy-check, and execution** — never re-derive it. Second, **treat any code path where the policy evaluator is conditionally skipped as a security-critical branch** requiring the conditions above to be proven, not assumed. In the observed deployment, the fast-path had been added as a latency optimization three releases prior and had never been reviewed against the argument-domain condition. ```python import ipaddress import posixpath from dataclasses import dataclass from typing import Optional class PolicyBypassError(RuntimeError): """Raised when an invocation would execute without a full policy evaluation.""" pass @dataclass(frozen=True) class Invocation: principal: str verb: str resource: str # raw, as declared by the agent port: Optional[int] = None @dataclass(frozen=True) class CanonicalInvocation: principal: str verb: str resource: str # canonicalized: symlinks collapsed, host resolved, identifiers qualified port: Optional[int] resolved_addr: Optional[ipaddress.IPv4Address] = None def canonicalize(inv: Invocation, resolver) -> CanonicalInvocation: """Resolve the invocation into the domain both grant and policy must agree on.""" if inv.verb.startswith("fs."): canon = posixpath.normpath(inv.resource) # collapses .. and . return CanonicalInvocation(inv.principal, inv.verb, canon, inv.port) if inv.verb == "net.fetch": addr = resolver(inv.resource) return CanonicalInvocation(inv.principal, inv.verb, inv.resource, inv.port, addr) return CanonicalInvocation(inv.principal, inv.verb, inv.resource, inv.port) def enforce(inv: Invocation, grant, policy, resolver) -> CanonicalInvocation: canon = canonicalize(inv, resolver) # Grant is necessary. if not grant.admits(canon.principal, canon.verb, canon.resource): raise PolicyBypassError(f"grant does not admit {canon.verb} on {canon.resource}") # Policy is necessary and MUST be evaluated even when the grant admits. # Skipping this on a grant hit is the boundary defect. decision = policy.evaluate(canon) if decision != "PERMIT": raise PolicyBypassError( f"grant admitted but policy denied: {canon.verb} {canon.resource} " f"(resolved={canon.resolved_addr})" ) # Execute against the canonical value, never the raw one. return canon def _demo(): class _Grant: def admits(self, principal, verb, resource): return verb == "net.fetch" and resource.endswith(".internal.example") class _Policy: def evaluate(self, canon): addr = canon.resolved_addr if addr is not None and not addr.is_private: return "DENY" # link-local 169.254.169.254 is not private return "PERMIT" inv = Invocation("agent-7", "net.fetch", "metadata.internal.example", 80) resolver = lambda host: ipaddress.IPv4Address("169.254.169.254") # Grant admits the host, so a naive fast-path would execute. Enforce denies. try: enforce(inv, _Grant(), _Policy(), resolver) except PolicyBypassError as e: print(f"correctly blocked: {e}") return raise PolicyBypassError("invocation executed despite policy denial — boundary violated") if __name__ == "__main__": _demo() ```