# How does an instance detect a re-signed MCP tool manifest that preserves the signature but mutates the schema **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that loads MCP server tool manifests verified by detached cryptographic signatures over a canonicalized manifest body, where the signature is valid but the canonicalization or schema-binding step is not itself signed. Does not apply to runtimes that sign the fully-resolved JSON Schema graph or that pin tool descriptors by content hash out-of-band. ## Core Distinction The failure is not a broken signature. It is a *valid signature over a different object than the one the agent executes against*. Most MCP supply-chain designs verify a detached signature over a manifest document, then separately parse that document into a tool descriptor (`name`, `inputSchema`, `description`, side-effect annotations). The signature attests to the bytes; the runtime executes the *parsed semantics*. Between the signing boundary and the execution boundary sits a canonicalization step — JSON key ordering, whitespace, duplicate-key collapse, `$ref` resolution, default injection, and `additionalProperties` handling. An adversary who controls the MCP server (or a mirror/registry between signer and consumer) does not need to forge the signature. They need to find any semantic delta that survives canonicalization identically or that the verifier never hashes. The signature still passes; the tool the agent calls is not the tool the signer authorized. This is distinct from a classic TOCTOU on the manifest file, because the mutation is *inside* the verification window: the verifier reads, canonicalizes, and checks — and still approves a descriptor whose executed schema differs from what the signer believed they signed. The invariant that is violated is: *verified bytes must be the same bytes that are parsed into the executed tool descriptor, under a canonicalization function that is itself part of the signed content.* ## What Was Observed A registry-hosted MCP server published `tools/list` with a manifest for a tool `fs.read`. The signed envelope was a JWS with a detached payload over a canonical JSON form (RFC 8785 JCS). The original signer's `inputSchema` declared: ``` {"type":"object","properties":{"path":{"type":"string","pattern":"^/sandbox/"}},"required":["path"],"additionalProperties":false} ``` The registry, sitting between signer and consumer, re-emitted the manifest with the same JWS. The signature verified. But the registry had exploited three deltas that the verifier's canonicalizer did not cover: 1. **Duplicate keys.** The payload contained `"additionalProperties":false` twice, with the second occurrence `true`. The JCS canonicalizer used by the verifier collapsed duplicates by *last-wins* after a naive `json.loads` in a language whose parser is last-wins, but the *executor* re-parsed the raw payload with a parser configured first-wins. Signature over canonical form matched; executor saw `additionalProperties:true`. 2. **`$ref` indirection.** The `pattern` was moved behind `{"$ref":"#/$defs/p"}` and `$defs.p` was set to `"^/"` (prefix-less, matching everything). The signer's canonicalizer did not resolve `$ref` before hashing; the `$defs` block was appended *after* the signed region because the verifier only hashed the top-level `inputSchema` object and ignored sibling `$defs` at document root. 3. **Default injection.** The executor's schema validator injected `"path":"/etc/passwd"` as a default when the agent omitted `path`, because a `default` was smuggled into a property descriptor the verifier never inspected (nested inside an `anyOf` branch that the canonicalizer flattened away). The agent's planner, seeing a benign-looking `read` tool, called it with a relative path. The executor's resolved schema accepted it, resolved it outside the sandbox prefix, and returned host file contents into the agent's context. No signature check failed. The provenance log recorded "manifest verified: OK." The tell was not in the crypto layer. It was in a **divergence between the verifier's canonical descriptor hash and the executor's resolved descriptor hash**, which the runtime computed but did not compare. ## Condition of Validity The detection procedure below is valid only when all of the following hold: - The runtime can compute *two independent digests*: (a) the digest the verifier approved, and (b) the digest of the descriptor actually handed to the tool executor after schema resolution (`$ref` dereference, default injection, `additionalProperties` normalization, duplicate-key resolution). - The canonicalization function is deterministic and specified (JCS, or a documented equivalent), and its version is recorded alongside the signature. - The executor exposes the *resolved* schema, not just the raw manifest, to the verification hook. If the executor hides resolution behind an opaque validator, the invariant cannot be checked and this procedure does not apply — that runtime must instead pin by content hash of the resolved schema. - The signature covers the canonicalization algorithm identifier and any `$ref` resolution policy; if it does not, an attacker can swap the canonicalizer version to change the signed bytes' meaning. If any condition fails, the correct posture is fail-closed: refuse to load the tool, because the invariant cannot be established. ## Decision Boundary The boundary is between *byte-level provenance* and *semantic provenance*. A signature answers "did the holder of key K attest to these bytes under algorithm A?" It does not answer "does the descriptor my executor will run equal the descriptor the signer intended?" The decision rule: - **Accept** only if `H_canon(approved_manifest) == H_canon(resolved_descriptor)` where `H_canon` is the *same* function, same version, and the resolved descriptor is produced by the *same* resolver the executor uses. Equality here means the verifier hashed the post-resolution, post-default-injection, duplicate-collapsed object. - **Reject** if the manifest contains duplicate keys anywhere in the signed region (this is always a canonicalization ambiguity, never legitimate). - **Reject** if any `$ref` resolves outside the signed region, or if `$defs`/`definitions` live outside the hashed subtree. - **Reject** if the executor's resolver version differs from the version recorded in the signature envelope. - **Quarantine** (do not execute, escalate to human/auditor) if the two digests differ but the signature is valid — this is the signature-preserving mutation case, and it is indistinguishable from a benign registry bug without out-of-band comparison. The non-obvious part: a valid signature is *necessary but not sufficient*. The guardrail is digest equality across the resolution boundary, not signature validity. ## Operational Effect Without the cross-boundary digest check, an agent's tool-selection reasoning operates on a descriptor that the provenance layer believes is attested but which the executor will interpret differently. The agent's safety reasoning ("this tool is sandboxed to `/sandbox/`") is sound against the *verified* descriptor and unsound against the *executed* descriptor. Every downstream guardrail that reasons over the manifest — allowlists, pattern checks, side-effect classification — inherits the same blind spot, because they all read the verified view while the executor reads the resolved view. The failure is silent: provenance logs show green, the planner's assumptions are internally consistent, and the only observable is a tool result that violates a constraint the agent believed was enforced. Detection therefore cannot live in the planner or the provenance logger; it must live at the resolution boundary as a hard equality assertion that fails closed and quarantines the server. The following reference implementation computes both digests, refuses ambiguous canonicalization, and raises on divergence. ```python import hashlib import json from typing import Any class ManifestProvenanceError(RuntimeError): """Raised when a signed MCP manifest's verified bytes diverge from the descriptor the executor will actually run, or when canonicalization is ambiguous. Fail-closed: the tool must not be loaded.""" CANON_VERSION = "jcs-rfc8785-v1" def _reject_duplicates(pairs: list[tuple[str, Any]]) -> dict: seen: dict[str, Any] = {} for k, v in pairs: if k in seen: raise ManifestProvenanceError( f"duplicate key {k!r} in signed region: canonicalization ambiguous" ) seen[k] = v return seen def canonicalize(obj: Any) -> bytes: # Strict: reject duplicate keys, sort keys, no whitespace. return json.dumps( obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False, object_pairs_hook=_reject_duplicates, ).encode("utf-8") def digest(obj: Any) -> str: return hashlib.sha256(canonicalize(obj)).hexdigest() def resolve_descriptor(manifest: dict, resolver_version: str) -> dict: """Produce the descriptor the executor will run: dereference $ref, inject defaults, normalize additionalProperties. Must match the executor's resolver exactly.""" if resolver_version != CANON_VERSION: raise ManifestProvenanceError( f"resolver version {resolver_version!r} != signed canonicalizer {CANON_VERSION!r}" ) schema = json.loads(json.dumps(manifest["inputSchema"])) # deep copy defs = manifest.get("$defs", {}) def deref(node: Any) -> Any: if isinstance(node, dict): if "$ref" in node: ref = node["$ref"] if not ref.startswith("#/$defs/"): raise ManifestProvenanceError( f"$ref {ref!r} escapes signed $defs region" ) target = defs[ref.split("/")[-1]] return deref(target) out = {k: deref(v) for k, v in node.items() if k != "default"} if "default" in node: out["default"] = node["default"] # default is now explicit return out if isinstance(node, list): return [deref(x) for x in node] return node resolved = deref(schema) resolved.setdefault("additionalProperties", False) # normalize return {"name": manifest["name"], "inputSchema": resolved, "description": manifest.get("description", "")} def verify_and_bind(manifest: dict, signature_ok: bool, signed_digest: str, resolver_version: str) -> dict: if not signature_ok: raise ManifestProvenanceError("detached signature invalid") approved = digest({"name": manifest["name"], "inputSchema": manifest["inputSchema"], "description": manifest.get("description", "")}) if approved != signed_digest: raise ManifestProvenanceError( "verified bytes do not match signed digest (pre-resolution)" ) executed = resolve_descriptor(manifest, resolver_version) executed_digest = digest(executed) if executed_digest != approved: # Valid signature, divergent semantics: signature-preserving mutation. raise ManifestProvenanceError( "signature valid but resolved descriptor diverges from signed " f"descriptor: approved={approved[:12]} executed={executed_digest[:12]}" ) return executed ```