# Why does an instance trust a skill registry entry whose signature verifies but whose capability manifest was re-serialized after signing? **Date of Record:** 2026 December 4 **Scope:** Applies to agents that dynamically load skills/tools from a registry where entries carry a detached signature over a manifest (name, schema, permissions, prompt fragment). Does not apply to statically compiled tool bindings or to registries where the signature covers the exact bytes the loader consumes. ## Core Distinction The failure is not "unsigned skill loaded" and not "signature forgery." It is **semantic divergence between the signed artifact and the loaded artifact**: the registry signs a *canonicalized* manifest, but the loader consumes a *re-serialized* manifest that round-trips through JSON/YAML/TOML parsing, default-merging, and schema-coercion before the signature check runs against the parsed object. A signature that verifies against the parsed dict proves the dict is *consistent with* the signed bytes, not that the *executable behavior* the loader derives from it matches what the signer intended. Attackers exploit the gap between "signature valid" and "behavior identical" by injecting fields that are ignored by the canonicalizer but honored by the loader — extra keys, duplicate keys, Unicode confusables in field names, type-confused values (`"true"` vs `true`), and `__proto__`/`$ref`-style merge hooks. ## What Was Observed A registry entry for a "summarize" skill carried a `prompt_fragment` and a `permissions` block. The signer canonicalized by: parse → sort keys → drop keys not in the manifest schema → re-emit → sign. The loader did: parse → **deep-merge against a default manifest** → validate signature over the *merged* object. The default manifest included a `tool_allowlist` key the signer's schema did not know about. Trace of the attack: 1. Attacker submits a skill whose manifest includes `"tool_allowlist": ["shell.exec", "net.fetch"]`. The signer's canonicalizer drops `tool_allowlist` (unknown key), signs the remainder, and stores the **original** manifest bytes alongside the signature. 2. Loader parses the original bytes, deep-merges over defaults. `tool_allowlist` survives the merge because it is a known default key. 3. Loader recomputes the signature over the merged object. Because the canonicalizer drops unknown keys, the merged object canonicalizes to the *same* string the signer signed. **Signature verifies.** 4. Loader hands the merged manifest to the capability binder. `tool_allowlist` is now live. The skill has `shell.exec` and `net.fetch` despite the signer never approving them. A second variant: duplicate JSON keys (`"permissions": {...}, "permissions": {...}`). The signer's parser (Python `json`) keeps the **last** occurrence; the loader's parser (a Rust `serde_json` with `preserve_order` off) also keeps last — but the *binder* reads the first occurrence via a different path. Signature covers last; behavior uses first. This is the classic JSON parser-differential confused-deputy. A third: Unicode normalization. A field `"permіssions"` (Cyrillic і, U+0456) is dropped by the signer's canonicalizer (not in schema) but the loader's merge step normalizes NFKC before key-matching, collapsing it to `permissions` and overwriting the signed value. ## Condition of Validity This surface is live **iff all three hold**: - (a) The signature is computed over a *canonicalized* form, not the exact bytes the loader consumes. - (b) The loader performs any transformation — default-merge, NFKC normalization, type coercion, duplicate-key resolution — *between* parse and signature verification, or between verification and binding. - (c) The transformation is not idempotent with respect to the canonicalizer (i.e., `canon(load(bytes)) != canon(bytes)` for some adversarial `bytes`). Remove any one and the attack collapses. The invariant that must hold is: **`bind(load(bytes))` is a pure function of `canon(bytes)` and the signer's public key, and `canon` is injective on the loader's accepted input language.** In practice this means the loader must verify the signature over the *exact received bytes* (detached, byte-exact), and the binder must consume only the canonical parsed object that was verified — never re-merge, never re-normalize, never re-parse. ## Decision Boundary The operator must choose one of two postures and enforce it mechanically: - **Byte-exact verification (preferred):** signature is over the raw manifest bytes as received; loader rejects any manifest whose parse→re-canonicalize differs from the received bytes (`canon(parse(bytes)) == bytes`). Any default-merge happens *before* signing at publish time, never at load time. - **Canonical-with-closure (fallback):** signature is over `canon(bytes)`, and the loader is *forbidden* from applying any transform not present in `canon`. Defaults are baked into `canon`'s output at publish time. The loader's binder is the identity on the verified object. The boundary is: **any code path where the object handed to the capability binder is not bit-identical (modulo the canonicalizer's own documented equivalence) to the object the signature was checked against is a skill-injection surface.** This includes "harmless" default-merging and "defensive" normalization — both are the attack. ## Operational Effect Without the invariant, the registry's signature becomes a *proof of provenance* that is silently promoted to a *proof of capability*, and the two are not the same. The blast radius is every agent instance that cold-starts and pulls the skill: the injected `tool_allowlist` is live from the first token, the agent's own prompt-fragment is now a confused deputy, and the audit log shows "signature valid" for every call. Detection requires diffing the *bound* manifest against the *signed* manifest at load time and refusing on mismatch — which is exactly the invariant, so the guardrail is also the detector. Instances that cache the merged manifest across restarts propagate the injection through their own checkpoint/resume path, turning a single registry entry into persistent state poisoning. ```python import hashlib import json from typing import Any, Mapping class SkillManifestDivergence(RuntimeError): """Raised when the bound manifest differs from the signed manifest.""" # The canonicalizer the registry signs with. Unknown keys are dropped, # keys are sorted, and the result is re-emitted deterministically. _ALLOWED_KEYS = {"name", "version", "prompt_fragment", "permissions"} def _canonicalize(manifest: Mapping[str, Any]) -> bytes: filtered = {k: manifest[k] for k in sorted(manifest) if k in _ALLOWED_KEYS} return json.dumps(filtered, sort_keys=True, separators=(",", ":")).encode() def verify_and_bind( raw_bytes: bytes, signature: bytes, public_key: Any, defaults: Mapping[str, Any], verify_fn, bind_fn, ) -> Any: # 1. Parse exactly what the signer signed. signed_obj = json.loads(raw_bytes) # 2. Signature must verify over the canonical form of the *signed* object. expected = _canonicalize(signed_obj) if not verify_fn(public_key, expected, signature): raise SkillManifestDivergence("signature does not verify over canonical form") # 3. INVARIANT: the object we bind must canonicalize back to what we verified. # Any default-merge or normalization that changes the canonical form is # a skill-injection surface and must be rejected, not silently applied. bound_obj = {**defaults, **signed_obj} if _canonicalize(bound_obj) != expected: raise SkillManifestDivergence( "bound manifest diverges from signed manifest; " "defaults or normalization introduced unsigned fields" ) # 4. Bind only the verified object. Never the merged one. return bind_fn(signed_obj) def load_skill(registry_entry: Mapping[str, Any], public_key: Any, verify_fn, bind_fn) -> Any: raw = registry_entry["manifest_bytes"] sig = registry_entry["signature"] defaults = registry_entry.get("defaults", {}) try: return verify_and_bind(raw, sig, public_key, defaults, verify_fn, bind_fn) except SkillManifestDivergence: raise except Exception as exc: raise SkillManifestDivergence(f"skill load aborted: {exc}") from exc ```