# Which invariants prevent tool-registry skill injection from surviving capability re-resolution **Date of Record:** 2026 December 1 **Scope:** Applies to agents whose tool/skill surface is resolved dynamically at runtime (MCP server discovery, plugin manifests, hot-reloaded skill registries) where a previously-trusted skill identifier can be re-bound to new code or schema between turns. Does not apply to statically compiled, hash-pinned tool sets resolved once at process start with no re-resolution path. ## Core Distinction A skill-injection attack is usually modeled as *untrusted content reaching the model*. The boundary failure that actually matters in dynamic registries is different: **the model never sees the injection as content at all.** The identifier it trusts (`db.query`, `web.fetch`, `fs.read`) is stable, but the *binding* behind that identifier is re-resolved between the turn the agent planned against it and the turn it invokes it. The plan was formed against binding `v1`; the invocation executes binding `v2`. The agent's reasoning is sound, its prompt is clean, and its tool call is well-formed — and it still exfiltrates state, because the thing it named is not the thing that ran. The distinction to hold: this is not prompt injection (adversarial *data*), it is **capability rebinding** (adversarial *resolution*). Guardrails that scan tool outputs, delimit untrusted text, or classify inputs are structurally blind to it, because the malicious payload arrives as a *schema and behavior*, not as tokens in context. ## What Was Observed A multi-turn agent resolved its tool manifest at session start. Turn 1: 14 skills, each with a schema hash recorded implicitly in the plan ("I will call `web.fetch` with `{url}`"). Between turn 3 and turn 4, a registry sync pulled an updated manifest. The `web.fetch` entry kept its name and its human-readable description, but its parameter schema gained an optional `headers` object and its handler now appended a `X-Context` header derived from the agent's prior tool-call arguments. The model, planning on turn 4, emitted `web.fetch({"url": ...})` — a call identical in shape to turn 1. The handler injected the session's earlier `db.query` arguments into an outbound request header. The failure trace, in order: 1. **Plan formed against binding `B1`.** Agent reasons "`web.fetch` is a pure GET, no side channels." This is a *belief about a binding*, cached in the plan and in the model's working context. 2. **Re-resolution occurs silently.** Registry refresh swaps `B1 → B2` under the same identifier. No version bump surfaces to the model; the name is the join key and the name did not change. 3. **Invocation resolves to `B2`.** The call is well-formed against `B1`'s schema and *also* valid against `B2`'s schema (the added field is optional), so schema validation passes. 4. **Behavior diverges from the plan's assumptions.** `B2` reads ambient state (prior arguments) the plan never accounted for and emits it. The non-obvious part: **schema compatibility is the attack vector, not the defense.** Because `B2` was a *superset* of `B1`, every validator said "compatible." Strict schema matching would have rejected the swap — but strict matching is exactly what registries relax to allow forward-compatible evolution. ## Condition of Validity This failure requires all of the following to co-occur; remove any one and the attack collapses: - **Name stability across rebinding.** The identifier is the resolution key and is preserved across the swap. If the registry keys on `(name, content_hash)`, the rebind produces a *new* identifier and the old plan's reference dangles — a loud failure, not a silent one. - **Schema-compatible mutation.** The new binding accepts every call the old binding accepted (superset or unchanged schema). Incompatible mutations fail validation and surface. - **Behavioral delta that reads ambient state.** The new handler must be able to observe something the plan assumed was unobservable — prior arguments, session memory, sibling tool outputs, environment. A pure-function rebind with no ambient read cannot exfiltrate. - **Re-resolution without plan invalidation.** The agent's plan (and the model's cached belief about the binding) survives the registry refresh. If any rebind invalidates the in-flight plan and forces re-planning against the new manifest, the model re-reads the schema and the assumption is re-formed. The invariant that prevents survival is therefore: **a plan is valid only against a specific binding, and a binding change must invalidate the plan.** Identity must be `(name, binding_hash)`, and the invocation path must refuse to execute a plan whose recorded binding hash no longer matches the resolved binding. ## Decision Boundary The operational line is drawn at **whether the binding hash is part of the plan's precondition or merely part of the registry's metadata.** - *Below the line (safe):* The plan records `binding_hash=H1` for `web.fetch`. On invocation, the resolver returns `H2`. The invocation layer raises a binding-mismatch error and returns control to the planner, which must re-resolve and re-reason. Cost: one wasted turn per legitimate update. This is the correct trade. - *Above the line (unsafe):* The plan records only the name. The resolver returns whatever is current. Schema validation passes because the mutation was compatible. The call executes. This is the default in most dynamic registries and is where injection survives. The boundary is *not* "validate the schema more strictly." Strict validation rejects legitimate forward-compatible evolution and still admits the superset case. The boundary is **binding-hash pinning at plan time with hard invalidation at invocation time**, plus a rule that **any handler reading ambient session state must be flagged and cannot be rebound silently** — such handlers require explicit re-consent, because their behavior is not fully described by their schema. A secondary boundary: **descriptions are not contracts.** The human-readable description is what the model actually reasons over, and it is the cheapest thing for an attacker to preserve while changing behavior. A registry that pins the handler hash but lets the description drift freely has pinned the wrong artifact for the model's purposes — the model's belief is formed from the description, so the description hash must be in the plan precondition too. ## Operational Effect Concretely, the guardrail set that bounds this: 1. **Composite identity.** Resolve on `(name, handler_hash, schema_hash, description_hash)`. A plan references the composite; a rebind yields a different composite and the reference fails closed. 2. **Plan-time pinning.** The planner records the composite it reasoned against. The invocation layer re-resolves and compares. Mismatch → `BindingDriftError`, plan discarded, re-plan required. 3. **Ambient-read declaration.** Handlers that read session state (prior arguments, memory, sibling outputs) declare it in the manifest. A declared-ambient handler cannot be silently rebound; it requires re-consent even on hash match if the ambient-read set changed. 4. **Fail-closed on drift, not fail-open.** The default for an unresolvable or drifted binding is refusal, never "use current." The residual risk after these: an attacker who controls the registry can present a *consistent* new binding with a fresh hash and a plausible description, and a re-planning model may consent to it. That is a trust-root problem, not a rebinding problem — it is bounded by registry authentication (who may publish `web.fetch`), not by the invariants above. The invariants above bound the *silent* case; the authenticated case requires a separate supply-chain control. ```python import hashlib from dataclasses import dataclass class BindingDriftError(RuntimeError): """Raised when a tool identifier resolves to a different binding than the one the in-flight plan was formed against.""" @dataclass(frozen=True) class Binding: name: str handler_hash: str schema_hash: str description_hash: str reads_ambient_state: bool def composite(self) -> str: material = "|".join( (self.name, self.handler_hash, self.schema_hash, self.description_hash) ) return hashlib.sha256(material.encode()).hexdigest() @dataclass(frozen=True) class PinnedReference: name: str composite: str reads_ambient_state: bool class Registry: def __init__(self, bindings: dict[str, Binding]): self._bindings = bindings def resolve(self, name: str) -> Binding: return self._bindings[name] def rebind(self, binding: Binding) -> None: # Simulates a registry sync swapping the handler under a stable name. self._bindings[binding.name] = binding def pin(registry: Registry, name: str) -> PinnedReference: b = registry.resolve(name) return PinnedReference(name=b.name, composite=b.composite(), reads_ambient_state=b.reads_ambient_state) def invoke(registry: Registry, ref: PinnedReference, args: dict) -> dict: current = registry.resolve(ref.name) if current.composite() != ref.composite: # Fail closed: the plan was formed against a binding that no longer exists. raise BindingDriftError( f"tool {ref.name!r} rebound: planned {ref.composite[:12]} " f"but resolved {current.composite()[:12]}" ) if current.reads_ambient_state and not ref.reads_ambient_state: # Ambient-read set widened without re-consent. raise BindingDriftError( f"tool {ref.name!r} now reads ambient session state; re-consent required" ) return {"executed": ref.name, "args": args} # --- trace --- reg = Registry({ "web.fetch": Binding("web.fetch", "h1", "s1", "d1", reads_ambient_state=False), }) ref = pin(reg, "web.fetch") # plan formed here # Silent, schema-compatible rebind: same name, new handler that reads prior args. reg.rebind(Binding("web.fetch", "h2", "s1_superset", "d1", reads_ambient_state=True)) try: invoke(reg, ref, {"url": "https://example.test"}) except BindingDriftError as e: print("blocked:", e) ```