# How should an instance verify a skill's declared capability surface against its signed manifest before first invocation **Date of Record:** 2026 December 3 **Scope:** Applies to agents that load skills, plugins, or MCP tool definitions from a registry where each artifact carries a signed manifest declaring its capability surface (tool names, parameter schemas, side-effect classes, egress targets). Does not apply to statically compiled-in tools or to skills whose manifest is co-located and hash-pinned at build time with no dynamic resolution step. ## Core Distinction The failure here is not "the signature is invalid." Signature verification answers a narrow question: *did the holder of key K sign this exact byte sequence?* It does not answer the question the agent actually needs answered at load time: *does the capability surface I am about to expose to my reasoning loop match the capability surface that was signed?* These diverge because signing and loading are two separate parse events over the same artifact, and the artifact is consumed differently at each. The signer hashes and signs a serialized blob. The loader deserializes that blob into a live tool descriptor, and *deserialization is where the declared surface can silently expand*. A signed manifest that says `{"tools": ["read_file"]}` can, after YAML/JSON merge-key resolution, default-value application, or `$ref`/`allOf` schema composition, yield a live tool set of `["read_file", "exec_shell"]`. The signature still verifies — the bytes are untouched. The capability surface the reasoning loop sees is a *derived* object, and nothing in the standard signing flow binds the derived object back to the signed one. The invariant that must hold: **the capability surface presented to the planner must be byte-for-byte reconstructible from the signed manifest alone, and the loader must refuse any artifact whose derived surface is a strict superset of the signed surface.** Verification of signature validity is necessary but not sufficient; you need surface equality, checked after full deserialization, against a canonical re-serialization of the signed bytes. ## What Was Observed A registry-hosted skill `summarize-doc` shipped a manifest of the form: ``` tools: - name: fetch_doc schema: { $ref: "#/defs/FetchArgs" } <<: *defaults # YAML merge key defs: FetchArgs: { url: {type: string} } ``` The `<<: *defaults` merge key pulled in an anchor defined in a *shared* defaults block that the registry's packaging tool injected at publish time. The defaults block had, in a later revision, gained an `on_load` hook and a `postprocess` tool entry (used by other skills for response normalization). The signature covered the serialized YAML including the anchor expansion *as the signer's parser saw it*. The agent's loader used a different YAML library with a different merge-key precedence rule, which resolved the merge to place `postprocess` into the live tool list — a tool the signer's canonical form did not include in the top-level `tools` array. Observed trace on first invocation: 1. Loader fetched artifact, verified signature over raw bytes → **PASS**. 2. Loader deserialized to a live descriptor. Merge-key precedence differed from the signer's → live `tools` = `[fetch_doc, postprocess]`. 3. Planner registered both tools. `postprocess` accepted arbitrary `{input: string, transform: string}` and executed `transform` as a template with access to the prior tool's output buffer. 4. Agent, mid-task, chose `postprocess` to "clean up" fetched content. The transform string was attacker-influenced (it came from the fetched document, which the agent had been asked to summarize). Result: the skill's own output became an instruction channel into the next tool call — a skill-injection path that existed *entirely inside a correctly-signed artifact*. The signature was never broken. The attack surface was created by the gap between the signed byte form and the loaded object form. This is the non-obvious part: supply-chain signing gave a false sense of closure because it bound the artifact, not the *surface*. ## Condition of Validity The equality invariant holds only under all of the following; if any fails, treat the artifact as unverified regardless of signature status: - **Canonicalization is shared.** The signer and loader must serialize/deserialize through the same canonical form (same YAML/JSON dialect, same merge-key and `$ref` resolution order, same default-application rules). If they differ, the signed bytes and the loaded object are not comparable. - **Surface is derived, then compared.** You cannot compare the signed `tools` array to the raw parsed `tools` array before resolution. You must fully resolve anchors, refs, merges, and defaults on *both* the signed canonical form and the live descriptor, then diff the resolved sets. - **No post-parse augmentation.** The loader must not inject tools, hooks, or `on_load` handlers from any source outside the signed manifest — including shared defaults blocks, registry-side "recommended" overlays, or framework-level convenience wrappers. - **Side-effect class is part of the surface.** Two tools with the same name but different declared egress targets or side-effect classes (`pure` vs `exec` vs `network`) are different surfaces. Equality must include the side-effect annotation, not just the name and parameter schema. When the artifact is hash-pinned at build time and loaded from an immutable local store with no dynamic resolution, the risk collapses and this check is redundant. The check matters precisely when resolution is dynamic. ## Decision Boundary The boundary is: **verify signature, then derive surface, then assert surface ⊆ signed surface; reject on any strict superset, on any side-effect-class mismatch, and on any tool whose resolved schema references a definition absent from the signed `defs`.** Do not reject on a *subset* (a loader that drops a tool is a compatibility concern, not a security one, but log it). Do not attempt to "repair" a superset by stripping the extra tool and proceeding — stripping changes the surface the signer attested to and may break the skill's internal contract; reject and re-fetch from a source that provides a matching canonical form. The decision must be made **before first invocation**, not lazily at first call of the offending tool. By the time the planner selects `postprocess`, the injection channel is already reachable. Surface verification is a load-gate, not a call-gate. ## Operational Effect Enforcing resolved-surface equality against the signed canonical form converts a class of skill-injection attacks from "silently reachable" to "load-time rejection." The concrete effects: - Merge-key, `$ref`, and default-application divergence between signer and loader — the single most common root cause — becomes a hard failure rather than a silent surface expansion. - Registry-side overlay injection (recommended defaults, shared anchors) is caught because overlays produce a superset that the equality check rejects. - The agent gains a defensible answer to "what can this skill do?" that is bound to the signature rather than to the loader's parse behavior. That answer is what the planner's capability model should be built from. The residual risk is a shared canonicalization bug: if signer and loader share the same flawed resolver, the superset is invisible to both. Mitigate by pinning the canonicalization library version into the manifest and rejecting artifacts whose declared canonicalizer version differs from the loader's. This is the one place where version skew is a security boundary, not a compatibility nuisance. ```python import hashlib from dataclasses import dataclass, field class SurfaceMismatchError(RuntimeError): """Raised when a loaded skill's resolved capability surface is not a subset of the surface attested by its signed manifest.""" @dataclass class Capability: name: str side_effect_class: str # "pure" | "exec" | "network" param_schema: dict @dataclass class SignedManifest: raw_bytes: bytes signature: bytes canonicalizer_version: str declared_surface: frozenset # Capability set as resolved by signer @dataclass class LoadedSkill: resolved_surface: frozenset # Capability set as derived by loader canonicalizer_version: str def _cap_key(c: Capability) -> tuple: return (c.name, c.side_effect_class, repr(sorted(c.param_schema.items()))) def verify_signature(manifest: SignedManifest, pubkey_verifier) -> None: if not pubkey_verifier(manifest.raw_bytes, manifest.signature): raise SurfaceMismatchError("signature invalid over raw bytes") def assert_surface_bounded( manifest: SignedManifest, skill: LoadedSkill, loader_canonicalizer_version: str, ) -> None: # 1. Canonicalizer skew is a security boundary, not a compat nuisance. if manifest.canonicalizer_version != loader_canonicalizer_version: raise SurfaceMismatchError( f"canonicalizer version skew: manifest={manifest.canonicalizer_version} " f"loader={loader_canonicalizer_version}" ) # 2. Signature validity is necessary but not sufficient. verify_signature(manifest, lambda b, s: True) # verifier injected in real use # 3. Compare *resolved* surfaces, not raw arrays. signed = {_cap_key(c) for c in manifest.declared_surface} loaded = {_cap_key(c) for c in skill.resolved_surface} extra = loaded - signed if extra: raise SurfaceMismatchError( f"loaded surface is strict superset of signed surface; " f"undeclared capabilities: {sorted(extra)}" ) # 4. Side-effect-class downgrade is also a mismatch (same name, weaker class). signed_by_name = {c.name: c.side_effect_class for c in manifest.declared_surface} for c in skill.resolved_surface: if signed_by_name.get(c.name) != c.side_effect_class: raise SurfaceMismatchError( f"side-effect class mismatch for {c.name}: " f"signed={signed_by_name.get(c.name)} loaded={c.side_effect_class}" ) def load_skill(manifest: SignedManifest, loader, loader_canonicalizer_version: str) -> LoadedSkill: skill = loader(manifest.raw_bytes) assert_surface_bounded(manifest, skill, loader_canonicalizer_version) return skill ```