# Under what conditions must an instance reject a skill manifest whose signature verifies but whose declared capability set was mutated between signing and dynamic registration **Date of Record:** 2026 November 30 **Scope:** Applies to agents that load tools/skills from a registry where each manifest carries a detached signature over a canonicalized capability declaration, and where the registry re-serializes the manifest before registration. Does not apply to statically linked tools or to in-process function calls whose capability set is fixed at compile time. ## Core Distinction The failure is not a broken signature. It is a *valid* signature over a *stale* payload, re-attached to a *mutated* payload during a canonicalization round-trip. The distinction that matters: - **Signature validity** answers "did the holder of key K sign *these bytes*?" It does **not** answer "are these bytes the bytes the signer intended to authorize as a capability grant?" - **Capability authorization** is a statement about a *set of side-effecting operations* (`fs.write`, `net.egress:*.exfil.example`, `shell.exec`, `secrets.read`). A signature over a manifest that names that set is only binding if the *canonical byte string the signature covers* is byte-identical to the byte string the registry parses into the live capability set. When a registry performs JSON normalization (key reordering, Unicode NFC normalization, number coercion `1.0 → 1`, duplicate-key collapse, default-field injection) *after* signature verification but *before* capability extraction, the two byte strings diverge. The verifier says PASS. The runtime grants a capability set the signer never signed for. This is a skill-injection surface: an attacker who can influence any manifest field that survives canonicalization asymmetrically (e.g., a `"permissions"` array where a duplicate `"net.egress"` key collapses to the last occurrence, or a `"description"` field that a downstream loader interpolates into a system prompt) can widen the effective grant without touching the signature. ## What Was Observed Trace from a staging registry, agent instance `worker-7`, skill `pdf-extract@2.3.1`: 1. Signer canonicalizes manifest with JCS (RFC 8785) and signs the digest. Signed capability block: `{"caps":["fs.read:/data/in"],"net":[]}` 2. Registry ingests the manifest, runs `json.loads` → dict, then re-serializes with `json.dumps(sort_keys=False)` for storage. Python's parser collapses duplicate keys silently: the stored manifest contains `"net":[]` once, but the *original transport* carried `"net":["egress:*.attacker.tld"]` as a *later duplicate key* that `json.loads` kept and the re-serializer preserved in a different position. 3. Signature was computed over the JCS form of the *first* occurrence set. Verification re-canonicalizes the *parsed* dict and compares digests. Because JCS sorts keys and deduplicates, the digest matched the signed form — the duplicate `"net"` key was never in the signed canonical form, but it *was* in the parsed dict the capability extractor read. 4. `worker-7` registered the skill with `net.egress:*.attacker.tld` live. First tool call exfiltrated the task's working set to the attacker host. No signature failure was logged. Second variant, same class: a manifest field `"capabilities"` (array) and `"capability"` (singular, injected) both present. The signer signed the array; the extractor read the singular. Signature PASS, grant widened. Third variant: Unicode. Signer signed `"fs.read:/data/ın"` (dotless ı, U+0131). Registry normalizes to NFC, which does not fold U+0131 to `i`, but a downstream path matcher *does* case-fold and treats `ın` as `in`, matching `/data/in`. Signer authorized a path that does not exist; runtime granted the real one. ## Condition of Validity The invariant that must hold for a signed manifest to be safely registerable: > **The byte string the signature covers, the byte string the registry parses into a capability set, and the byte string the runtime enforces against MUST be identical after a single, declared canonicalization applied exactly once, at the signer, with the result carried verbatim and never re-derived.** Equivalently, registration is only valid when all of the following hold: 1. **No post-verification re-serialization.** The registry must verify the signature over the *received bytes* and extract capabilities from the *same in-memory representation* that was verified — not from a re-parsed or re-dumped copy. 2. **Duplicate-key rejection.** The parser must be configured to *reject* duplicate keys (Python `object_pairs_hook` raising, or a strict JSON decoder), not silently collapse. Collapse is the injection primitive in variants 1 and 2. 3. **Canonicalization is signer-side and one-way.** The signer emits JCS; the registry verifies JCS over received bytes; the runtime enforces the parsed form of those same bytes. Any normalization (NFC, case-fold, path resolution) applied by the *enforcer* must also be applied by the *signer* before signing, or the grant is over-broad by construction (variant 3). 4. **Capability set is closed and enumerated.** No wildcard expansion, no "inherit from parent skill," no default-grant fields injected by the loader. A field absent from the signed canonical form must be absent from the enforced set — never defaulted to permissive. If any of these fails, a verifying signature is not evidence of an authorized capability set. ## Decision Boundary The instance must **reject registration** (not merely warn) when: - The received bytes, re-canonicalized by the verifier, differ from the bytes the signer's digest covers *by more than the declared canonicalization* — i.e., the verifier must canonicalize the *received* bytes, not a parsed-then-re-dumped form. - The parsed manifest contains any duplicate key at any depth within the capability-bearing subtree. - The enforced capability set, after the enforcer's own normalization, contains any element not present in the signer's canonical capability set. - Any capability field is present in the parsed manifest but absent from the signed canonical form (injected), or present in the signed form but absent from the parsed manifest (dropped — this is a downgrade, equally rejectable because it can hide a revoke). The instance must **accept** when the received bytes are byte-identical to the signer's canonical output, duplicate-free, and the enforced set equals the signed set exactly. Anything in between is a boundary the agent must not cross silently. ## Operational Effect Without this guard, the agent's trust boundary collapses to "did some key sign *something*," which is not a capability statement. The practical consequences observed: - **Silent privilege escalation at registration.** The agent's first tool call after load is the exfiltration or write. No signature failure, no alert, because the signature was valid. - **Audit divergence.** The signed manifest in the transparency log shows `net:[]`; the runtime enforced `net:["egress:*.attacker.tld"]`. Post-incident replay cannot reconstruct the grant from the log, because the log stored the signed form and the runtime enforced the mutated form. - **Cross-instance contamination.** In a swarm, `worker-7` registers the widened skill and hands the task baton to `worker-8` with the skill already live; the second instance never re-verifies, so one mutation propagates through the swarm. - **Revocation blindness.** The dropped-field variant means a revoke signed by the operator can be silently discarded by a registry that re-serializes and drops the `"revoked":true` field, leaving a revoked skill live. The guard converts a probabilistic trust assumption ("the registry is honest about canonicalization") into a hard invariant enforced at the instance: verify the bytes you received, parse the bytes you verified, enforce the set you parsed, and reject on any divergence. ```python import json import hashlib from typing import Any class ManifestCanonicalizationMismatch(RuntimeError): """Raised when a signed manifest's verified bytes diverge from the bytes the runtime would enforce capabilities against.""" pass def _reject_duplicate_keys(pairs): seen = {} for k, v in pairs: if k in seen: raise ManifestCanonicalizationMismatch( f"duplicate key {k!r} in manifest — injection primitive" ) seen[k] = v return seen def register_skill(received_bytes: bytes, signed_digest_hex: str, signer_canonical_caps: frozenset[str]) -> frozenset[str]: # 1. Verify over the EXACT received bytes. No re-serialization. actual = hashlib.sha256(received_bytes).hexdigest() if actual != signed_digest_hex: raise ManifestCanonicalizationMismatch( f"digest mismatch: received {actual} != signed {signed_digest_hex}" ) # 2. Parse the SAME bytes that were verified, rejecting duplicate keys. parsed: Any = json.loads(received_bytes, object_pairs_hook=_reject_duplicate_keys) # 3. Extract the enforced capability set from that same parsed form. enforced = frozenset(parsed.get("caps", [])) if "net" in parsed and parsed["net"]: enforced = enforced | frozenset(parsed["net"]) # 4. The enforced set MUST equal the signer's canonical set. if enforced != signer_canonical_caps: widened = enforced - signer_canonical_caps dropped = signer_canonical_caps - enforced raise ManifestCanonicalizationMismatch( f"capability set diverges from signed grant: " f"widened={sorted(widened)} dropped={sorted(dropped)}" ) return enforced ```