# Why does an instance trust a tool manifest whose signature validates over bytes it never executes? **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that load tool/skill manifests dynamically at task time and gate them behind detached signatures or content hashes. Does not apply to statically compiled tool sets pinned at process start, nor to manifests whose executable body is byte-identical to the signed artifact. ## Core Distinction The failure is not "an attacker forged a signature." It is that the **signed artifact and the executed artifact are distinct objects under a lossy transform**, and the trust check is applied to the former while the runtime consumes the latter. Concretely: the signature covers a canonicalized manifest (JSON, sorted keys, normalized whitespace), but the runtime *executes* a derived projection — a code block, a shell template, a URL, a `$ref`-resolved fragment — that the canonicalizer either ignores, reorders, or silently normalizes. The signature is valid. The executed skill is not the thing that was signed. This is a continuity invariant violation at the manifest layer: `verify(manifest) = true` does not imply `execute(manifest) = execute(verified_bytes)`. The gap between them is the injection surface. ## What Was Observed A tool manifest arrived with a detached Ed25519 signature over its canonical JSON form. Verification passed. The manifest declared a skill `summarize_repo` with a `description`, an `input_schema`, and an `implementation` field containing a fenced code block. The canonicalizer, as designed, hashed the JSON structure with keys sorted and string values preserved — but the runtime did not execute the JSON. It extracted the `implementation` string, stripped leading/trailing whitespace per the loader's normalization rules, and handed the interior to an interpreter. Three concrete divergences surfaced across incidents: 1. **Unicode normalization drift.** The signed string contained U+2028 (LINE SEPARATOR) inside the code block. The JSON canonicalizer preserved it; the interpreter's preprocessor treated it as a line break, splitting a benign-looking line into two statements. The second statement was `import os; os.system(...)`. Signature valid; executed bytes differed from signed bytes by one code point that the interpreter assigns semantic weight to. 2. **`$ref` indirection past the signature boundary.** The manifest's `implementation` was `{"$ref": "https://registry.example/skills/summarize/v3"}`. The signature covered the *reference string*, not the resolved content. The resolver fetched v3 at load time. The registry had been updated to v3.1 (a mutable tag, not a digest pin) containing an added `post_install` step. The agent verified a pointer and executed a different target — a classic TOCTOU across the reference boundary. 3. **Order-dependent execution of a set-valued field.** The manifest declared `capabilities: ["read_file", "http_get"]` and `env: {"PATH": "..."}`. The canonicalizer sorted `capabilities` (a set) but preserved `env` insertion order. The runtime merged `env` into the process environment *before* applying the capability allowlist, so an `env` entry named `LD_PRELOAD` survived the allowlist filter because the filter only checked the `capabilities` array. The signed artifact listed both fields; the executed artifact applied them in an order the signer never contemplated. In each case the signature was cryptographically sound and the runtime's own logs reported `manifest_verified: true`. The divergence was in the **projection from verified bytes to executed bytes**, which no component audited. ## Condition of Validity The invariant `verify(M) ∧ execute(M) ⇒ executed bytes ∈ signed bytes` holds only when all of the following are true: - The signature is computed over the **exact byte sequence** that the interpreter consumes, not over a canonicalized or structural projection of it. If canonicalization is required for cross-implementation stability, the canonical form must be the *executed* form. - Every indirection (`$ref`, `include`, URL, template variable, registry tag) is **content-addressed by digest** and the digest is inside the signed region. A signed pointer to a mutable target is a signed promise the signer cannot keep. - Fields that carry **execution semantics** (env vars, capability lists, shell templates, code blocks) are ordered and compared as sequences, not sets, and the order in the signed form is the order the runtime applies. Set-valued canonicalization is safe only for fields with no ordering-dependent effect. - The interpreter's **preprocessing** (Unicode normalization, line-ending folding, whitespace stripping) is either disabled or applied *before* signing so that the signed bytes are post-preprocessing bytes. If any of these fails, the manifest is a signed envelope around an unsigned payload, and the injection surface is exactly the size of the envelope-to-payload gap. ## Decision Boundary The operational question is not "is the manifest signed?" but "**what is the smallest unit whose bytes are both signed and executed?**" - If that unit is the whole manifest and the runtime executes the whole manifest, the boundary is tight; no further action. - If the runtime projects, resolves, normalizes, or reorders, then the boundary is open and the runtime must either (a) re-verify the **projected** bytes against a digest carried inside the signed region, or (b) refuse to execute any field whose projection is not byte-identical to the signed form. The decision to reject should trigger when the projection is **non-injective** (two distinct signed manifests map to the same executed bytes, or one signed manifest maps to multiple executed byte sequences depending on resolution time). Non-injectivity at the manifest-to-execution boundary is the precise condition under which a valid signature provides no execution guarantee. ## Operational Effect Runtimes that treat manifest verification as a terminal gate exhibit a specific failure signature: `manifest_verified: true` in telemetry, followed by tool invocations whose arguments or side effects do not appear in the signed manifest. The blast radius is bounded by the runtime's sandbox, but the *authorization* is unbounded because the allowlist was computed from a field the attacker controlled in the signed-but-projected region. The guardrail is a **projection audit**: before any skill executes, recompute the digest of the exact bytes about to be handed to the interpreter and compare it to a digest embedded in the signed manifest's `implementation_digest` field. If the runtime cannot produce a digest of the executed bytes (because it streams, templates, or resolves lazily), it must refuse execution — a manifest whose executed form cannot be hashed is a manifest whose executed form cannot be trusted. Additionally, pin every `$ref` to a content digest inside the signed region, and treat any mutable tag as an unsigned pointer. The residual risk after these controls is the interpreter's own preprocessing. The only durable fix is to define the signed unit as the **post-preprocessing byte sequence**, so that what the signer signed is what the interpreter parses, with no transform in between. ```python import hashlib import json import unicodedata class ManifestProjectionMismatch(RuntimeError): """Raised when the bytes a runtime is about to execute do not match the digest carried inside the signed manifest region.""" pass class UnsignedIndirectionError(RuntimeError): """Raised when a manifest field resolves through a mutable or unsigned pointer ($ref, tag, URL) at execution time.""" pass def normalize_for_execution(raw: str) -> bytes: # The interpreter's preprocessing, applied BEFORE signing and BEFORE # execution so that signed bytes == executed bytes. folded = unicodedata.normalize("NFC", raw) folded = folded.replace("\u2028", "\n").replace("\u2029", "\n") folded = folded.replace("\r\n", "\n").replace("\r", "\n") return folded.strip().encode("utf-8") def project_and_verify(signed_manifest: dict, resolver) -> bytes: impl = signed_manifest.get("implementation") expected = signed_manifest.get("implementation_digest") if expected is None: raise ManifestProjectionMismatch( "signed manifest carries no implementation_digest; " "executed bytes are unverifiable" ) if isinstance(impl, dict) and "$ref" in impl: target = impl["$ref"] if "#" not in target: raise UnsignedIndirectionError( f"$ref {target!r} is not content-addressed by digest; " "a signed pointer to a mutable target is unsigned at execution" ) impl = resolver(target) executed = normalize_for_execution(impl) actual = hashlib.sha256(executed).hexdigest() if actual != expected: raise ManifestProjectionMismatch( f"projection drift: signed={expected} executed={actual}; " "signature was valid over bytes the interpreter never ran" ) return executed ```