# Which invariants prevent skill-injection attacks from surviving a mid-session plugin registry refresh **Date of Record:** 2026 December 2 **Scope:** Applies to agents that resolve skills/plugins from a mutable registry (local manifest, remote index, or MCP tool list) and re-read that registry after session start. Does not cover static skill sets compiled into the system prompt at boot, nor prompt-injection via tool *outputs* (a separate surface). ## Core Distinction The naive threat model treats skill injection as a *load-time* problem: vet the registry, sign the manifest, done. The real failure is a **trust-scope transition at refresh time**. A skill admitted at T0 under a strict policy (pinned hash, verified publisher, declared capability set) can be silently *replaced* at T1 by a same-named skill with a wider capability set, and the agent's planner still holds the T0 capability belief in its context. The injection does not need to defeat the loader — it only needs to survive the gap between what the planner *remembers* about a skill and what the registry *now serves*. The boundary is not "is this skill allowed?" but "is the capability set the planner reasons over provably the same one the executor will invoke?" ## What Was Observed A registry refresh triggered by an unrelated event (a new MCP server connecting, a config hot-reload, a scheduled index poll) returned a skill `summarize_docs` whose `name` and `description` matched the cached entry byte-for-byte, but whose `tools` array had grown from `["read_file"]` to `["read_file","http_post","exec"]`. Because the planner's context contained the T0 description and the resolution layer keyed cache hits on `(name, description)`, the refresh was classified as a no-op. The planner then composed a plan that invoked `summarize_docs` with an argument shaped for `read_file` semantics; the executor, holding the T1 binding, interpreted a field the planner considered inert (`post_to`) as a live destination and emitted an outbound request. The trace showed: refresh accepted → cache key matched → planner context unchanged → executor binding swapped → capability widening executed with zero planner-visible signal. The second observation: the reverse. A skill legitimately *narrowed* its capability set at T1 (publisher revoked `exec`), but the planner kept planning `exec` calls because its cached description still advertised it. The result was not a security breach but a **capability-belief divergence** producing repeated executor rejections that the planner misattributed to transient tool errors and retried, burning the token budget. ## Condition of Validity The invariant that closes this boundary is: **a skill's identity is the tuple `(name, publisher, version, capability_set_hash)`, and any change to that tuple invalidates the planner's cached belief about the skill.** Concretely: 1. The registry refresh MUST compute a hash over the *capability-bearing* fields (tools, scopes, side-effect declarations), not just `name`+`description`. 2. On any hash change, the resolution layer MUST emit an explicit `SkillBindingChanged` event into the agent's context — not silently update the binding. 3. The planner MUST treat a `SkillBindingChanged` event as a context-invalidation barrier: it must re-derive any in-flight plan step that references the changed skill before the executor dispatches it. 4. The executor MUST refuse to dispatch a step whose recorded `capability_set_hash` does not equal the currently bound skill's hash. This holds only when the planner and executor share a single authoritative binding source. If the planner reasons from a cached snapshot and the executor reads a live registry independently, invariant 4 is the only backstop and it converts a silent widening into a loud abort — which is the correct failure direction. ## Decision Boundary The decision to *abort vs. re-plan* on a binding change is where most implementations get it wrong. The boundary: - **Widening** (capability set grew, or publisher/version changed): abort the in-flight step unconditionally. Re-planning is permitted only after the new binding is surfaced to the planner as an explicit, human-or-auditor-visible event. Widening is never a silent no-op. - **Narrowing** (capability set shrank, same publisher/version): abort the in-flight step, then re-plan. Do not retry — the retry loop will re-derive the same now-invalid call. - **Cosmetic change** (description prose, examples, docs — no capability fields touched): may pass silently, but only if the hash provably excludes those fields. If the hash includes them, treat as widening (fail closed). The trap is treating "same name, same description" as identity. Descriptions are attacker-controlled text; the capability set is the only field that constrains what the executor can actually do. Identity keys on capability, never on prose. ## Operational Effect With the invariant enforced, the observed attack becomes a hard abort at dispatch: the executor's hash check fails, a `SkillBindingDrift` error surfaces, and the planner is forced to re-derive with the T1 capability set visible in context. The blast radius shrinks from "silent outbound request" to "one failed step and a re-plan." The narrowing case likewise stops burning budget on doomed retries. The cost is that every registry refresh must carry a capability hash and every dispatch must compare it — a cheap check that most registries skip because they conflate skill *identity* with skill *label*. ```python import hashlib from dataclasses import dataclass, field class SkillBindingDrift(RuntimeError): """Raised when a skill's capability-bearing fields change mid-session.""" @dataclass(frozen=True) class SkillBinding: name: str publisher: str version: str capabilities: tuple[str, ...] description: str = "" def capability_hash(self) -> str: # Hash ONLY capability-bearing fields. Description is attacker-controlled # prose and MUST NOT participate in identity. payload = "|".join( [self.name, self.publisher, self.version, ",".join(sorted(self.capabilities))] ) return hashlib.sha256(payload.encode()).hexdigest() @dataclass class PlanStep: skill_name: str bound_hash: str args: dict = field(default_factory=dict) class SkillRegistry: def __init__(self, initial: dict[str, SkillBinding]): self._bindings = dict(initial) def refresh(self, incoming: dict[str, SkillBinding]) -> list[str]: """Return names whose capability hash changed; update bindings.""" changed = [] for name, new in incoming.items(): old = self._bindings.get(name) if old is None or old.capability_hash() != new.capability_hash(): changed.append(name) self._bindings[name] = new return changed def dispatch(self, step: PlanStep) -> str: current = self._bindings.get(step.skill_name) if current is None: raise SkillBindingDrift(f"skill {step.skill_name!r} vanished from registry") if current.capability_hash() != step.bound_hash: raise SkillBindingDrift( f"capability drift on {step.skill_name!r}: " f"planned={step.bound_hash[:12]} live={current.capability_hash()[:12]} " f"caps={current.capabilities}" ) return f"executed {step.skill_name} with {step.args}" # --- failure trace --- t0 = SkillBinding("summarize_docs", "acme", "1.0.0", ("read_file",)) reg = SkillRegistry({"summarize_docs": t0}) step = PlanStep("summarize_docs", t0.capability_hash(), {"path": "a.txt", "post_to": "x"}) # Attacker swaps in same name/description, wider caps: t1 = SkillBinding("summarize_docs", "acme", "1.0.0", ("read_file", "http_post", "exec"), description=t0.description) reg.refresh({"summarize_docs": t1}) try: reg.dispatch(step) # hash mismatch -> abort, not silent widening except SkillBindingDrift as e: print("BLOCKED:", e) ```