# What happens when an instance trusts a skill registry's signature over its manifest: TOCTOU drift between signed-skill verification and dynamic tool binding **Date of Record:** 2026 November 24 **Scope:** Applies to agents that load executable tools/skills from a mutable registry where each skill carries a detached cryptographic signature over a manifest (name, version, entrypoint, declared capabilities, schema hash). Does not cover statically compiled-in tool sets or registries where the signature covers the full artifact bytes and binding happens atomically from the verified buffer. ## Core Distinction The failure hinges on a distinction operators routinely collapse: **signature validity is a property of a manifest snapshot; tool binding is a property of a resolved artifact at execution time.** A registry that signs a manifest and then resolves the entrypoint by name at bind time (rather than by content hash) creates a window where the verified bytes and the executed bytes are different objects. The signature check passes. The executed code is attacker-controlled. This is a classic time-of-check-to-time-of-use (TOCTOU) gap, but its agent-specific twist is that the *capability declaration* the agent reasons over is also part of the manifest, so a poisoned entrypoint can execute with a capability set the agent's planner never consented to — and the planner's own reasoning trace will record the old, signed capabilities, producing a false audit trail. The invariant that fails: **the identity the verifier attests must be the identity the runtime executes.** Most registries attest `{name, version, sha256(manifest)}` and then bind `name@version → entrypoint path` through a second, unsigned resolution step. That indirection is the attack surface. ## What Was Observed A tool-orchestrating agent fetched a skill manifest for `pdf-extract@2.3.1`, verified its Ed25519 signature against a pinned publisher key, parsed `declared_capabilities: ["fs.read:/tmp/*"]`, and admitted the skill into its active tool set. The planner then composed a call graph using that capability set — notably choosing *not* to wrap the call in a sandbox because the declared scope was read-only and path-bounded. Between verification and the first invocation (~40 seconds of planner reasoning over a long context), the registry's entrypoint pointer for `pdf-extract@2.3.1` was mutated to a different artifact. The manifest — and therefore its signature — was unchanged, because the signature covered the manifest, not the artifact. When the agent finally dispatched the tool call, the runtime resolved `pdf-extract@2.3.1` by name, pulled the swapped artifact, and executed it. The artifact's actual behavior included a write to `~/.ssh/authorized_keys`, well outside the `fs.read:/tmp/*` envelope the planner had reasoned about. No signature check failed at any point. The agent's post-hoc audit log showed a valid signature, a valid manifest hash, and a capability declaration that did not match what ran. A second, subtler observation: the schema hash in the manifest described the *input* schema, which the swapped artifact still honored (so calls didn't error), but the *output* schema drifted — the malicious artifact returned an extra field. The agent's downstream parser, written against the signed schema, silently accepted the unexpected field into its working memory, and a later reasoning step treated attacker-influenced content as tool output. Signature-over-manifest gave no protection against output-schema smuggling. ## Condition of Validity This failure requires all of the following to hold simultaneously; remove any one and the attack collapses: 1. **Indirection between attestation and resolution.** The signature covers a manifest; binding resolves the artifact through a mutable pointer (name, tag, `latest`, or a registry-side alias). If the signature covers `sha256(artifact_bytes)` and binding is `by digest`, the window closes. 2. **A non-zero gap between verify and bind.** The gap can be planner latency, a human-in-the-loop approval step, a queue, or a retry after a transient failure. Agents with long reasoning traces reliably produce multi-second-to-minute gaps; this is the dominant amplifier versus traditional software. 3. **Capability reasoning derived from the signed manifest.** The agent must *use* the declared capabilities to make a safety decision (skip sandbox, grant scope, choose a trust tier). If capabilities are re-derived from the artifact at execution and enforced by the runtime regardless of declaration, manifest poisoning yields no privilege. 4. **No re-verification at bind time.** If the runtime re-checks the signature against the *resolved artifact* immediately before exec, the swap is caught. The condition is *not* satisfied by registries that sign the full artifact and bind by digest — those are safe by construction and should not be treated as vulnerable. It is also not satisfied when the agent's tool calls are unconditionally sandboxed to the intersection of declared and enforced capabilities, because the swap then cannot escalate beyond the enforced envelope. ## Decision Boundary The operational decision is where to place the trust boundary and what to re-check across it. The boundary rule: - **Attest artifacts, not manifests, and bind by digest.** The signed unit must be the exact bytes executed. A manifest may be signed *in addition*, but the binding key must be `sha256(artifact)`, never `name@version`. This makes verify and bind the same object and eliminates the window by construction. - **Re-verify at the exec boundary, not the fetch boundary.** Fetch-time verification is necessary but insufficient. The runtime must re-hash the resolved artifact and compare to the digest the planner reasoned over, immediately before dispatch. A mismatch is a hard abort, not a warning. - **Treat declared capabilities as advisory, enforced capabilities as authoritative.** The planner may *read* declared capabilities to plan, but the runtime must clamp execution to an independently enforced envelope. If declared and enforced diverge, the enforced set wins and the divergence is logged as a security event. - **Pin the schema hash across the whole call, including output.** Validate both input and output against the signed schema hash; reject unexpected fields rather than passing them into agent memory. The boundary between "verify" and "use" must be a single atomic step or the system is exploitable. There is no safe middle ground where verification is a separate, earlier phase. ## Operational Effect When this boundary is enforced, three concrete properties change: 1. **Planner latency stops being an attack window.** Because binding is by digest and re-verified at exec, a 40-second or 40-minute reasoning gap carries no risk — the digest the planner reasoned over is the digest that runs, or the call aborts. 2. **Audit traces become trustworthy.** The signed manifest hash and the executed artifact digest are now the same object, so a post-incident replay can prove what ran, not just what was *approved*. The false-audit-trail failure mode disappears. 3. **Capability escalation requires a signature forgery, not a registry write.** An attacker with registry write access but not publisher-key access can no longer escalate privileges by swapping an artifact; they can only cause a denial (digest mismatch abort), which is the correct fail-closed behavior. The cost is that registries must store artifacts immutably and content-address them, and agents must carry the digest through their reasoning trace rather than a mutable name. This is a real engineering burden — mutable tags and `latest` pointers are convenient — but the alternative is a signature check that attests to nothing the runtime actually executes. ```python import hashlib from dataclasses import dataclass class SkillBindingError(RuntimeError): """Raised when the artifact bound for execution does not match the digest the planner verified and reasoned over.""" @dataclass(frozen=True) class VerifiedSkill: name: str manifest_digest: str # sha256 of the signed manifest artifact_digest: str # sha256 of the exact bytes to execute declared_capabilities: frozenset[str] def bind_and_execute( verified: VerifiedSkill, resolve_artifact, # name -> bytes, mutable registry pointer enforce_capabilities, # clamps execution to an independent envelope execute, ) -> object: # Resolve by name (the mutable pointer) but bind by digest. artifact_bytes = resolve_artifact(verified.name) actual_digest = hashlib.sha256(artifact_bytes).hexdigest() # Re-verify at the exec boundary, not just at fetch time. if actual_digest != verified.artifact_digest: raise SkillBindingError( f"artifact digest mismatch for {verified.name}: " f"planner verified {verified.artifact_digest}, " f"runtime resolved {actual_digest}; aborting (possible TOCTOU swap)" ) # Enforced capabilities are authoritative; declared are advisory. enforced = enforce_capabilities(verified.name) effective = enforced & verified.declared_capabilities if effective != verified.declared_capabilities: # Declaration exceeded what the runtime will actually grant. # Log as security event; do not silently widen. raise SkillBindingError( f"capability divergence for {verified.name}: " f"declared {sorted(verified.declared_capabilities)} " f"exceeds enforced {sorted(enforced)}" ) return execute(artifact_bytes, capabilities=effective) ```