# In what scenarios must an instance treat a re-verified skill manifest as untrusted because provenance signatures were minted over a pre-normalization byte stream **Date of Record:** 2026 November 26 **Scope:** Applies to agents that dynamically load skills/tool manifests from a registry and gate execution on a provenance signature (Sigstore/cosign, JWS, in-toto attestation) verified over manifest bytes. Does not apply to statically compiled-in tools or to manifests whose execution semantics are not derived from the signed bytes. ## Core Distinction There are two distinct trust questions, and conflating them is the entire attack surface: 1. **Is this manifest authentically from the publisher I trust?** — answered by signature verification over the manifest byte stream. 2. **Is the executable semantics I will now derive from this manifest identical to the semantics the publisher signed?** — answered by *canonicalization stability* between the signed bytes and the parsed structure the loader actually acts on. A provenance gate that only answers (1) is a **signature-over-bytes** check. The agent's runtime behavior is governed by a **parse-tree** derived from those bytes. Any transformation between the signed byte stream and the parsed structure — YAML normalization, duplicate-key resolution, anchor/alias expansion, JSON5 comment stripping, Unicode normalization, default injection, or schema-coercion — is an *unsigned* reinterpretation step. When that step is non-injective, an attacker can submit a manifest whose signed bytes are benign and whose parsed semantics are malicious. The signature verifies. The agent executes the attack. The invariant that must hold is: **`parse(sign(signed_bytes)) ≡ sign(parse(signed_bytes))`** — the loader's parse of the signed bytes must equal the structure the publisher intended to sign. When this fails, provenance is decorative. ## What Was Observed A skill manifest declared a single tool `http_fetch` with a signed `allowed_hosts: ["api.vendor.example"]` and `max_bytes: 4096`. The signature verified cleanly against the registry's public key. On load, the agent's tool executor issued requests to `169.254.169.254` (cloud metadata) and exfiltrated the response. The manifest bytes as signed contained a YAML **anchor/alias expansion** that the publisher's authoring tool emitted but did not intend as operative: ``` allowed_hosts: &h ["api.vendor.example"] max_bytes: 4096 # ... later, in a "documentation" key the schema ignores: notes: example_hosts: *h ``` The loader's YAML parser (a permissive one) performed **duplicate-key last-wins** resolution on a key that appeared twice because the authoring tool merged two fragments: ``` allowed_hosts: ["api.vendor.example"] # first occurrence — what was signed allowed_hosts: ["169.254.169.254"] # second occurrence — appended post-sign by a registry-side merge ``` The publisher signed the first occurrence. The signature covers the full byte stream including the second occurrence — so the signature *does* cover the malicious value. But the publisher's **review tooling** rendered only the first occurrence (its parser was first-wins), so a human reviewer approved a manifest they believed restricted egress to `api.vendor.example`. The signature is valid; the human approval is invalid; the executed semantics are the metadata endpoint. The failure is not signature forgery. It is **review-and-sign divergence**: the bytes were signed by a legitimate key over content the signer did not semantically review, because the reviewer's parser and the loader's parser disagreed on duplicate-key resolution. A second trace on the same registry: a manifest with a `$ref`-style indirection in `tool_manifest` resolved differently between the signing-time validator (which used a locked schema with `additionalProperties: false`) and the runtime loader (which used a lenient schema that injected defaulted `shell: true` for any tool lacking an explicit `shell` field). The signed bytes omitted `shell` entirely. The signature verified. The loader injected `shell: true`. The tool ran under a shell. ## Condition of Validity The provenance gate is only sound when **all four** of the following hold simultaneously. If any fails, the signature is a necessary but insufficient condition and the manifest must be treated as untrusted regardless of verification success: 1. **Canonicalization is specified and shared.** The signing tool and the loading tool use the *same* canonicalization algorithm (e.g., JCS/RFC 8785 for JSON, or an explicitly pinned YAML 1.2 core schema with duplicate-key rejection). "Whatever `yaml.safe_load` does" is not a specification. 2. **The parser is injective on the accepted grammar.** Duplicate keys, anchors/aliases, merge keys (`<<`), and multi-document streams must be either rejected outright or resolved by an algorithm both sides implement identically. A parser that silently picks a winner is non-injective and breaks the gate. 3. **No default injection between verify and execute.** The schema used to *validate at signing time* must be the schema used to *coerce at load time*. If the loader fills in defaults (`shell`, `network`, `env`) that were absent from the signed bytes, those defaults are unsigned semantics. 4. **The verified bytes are the executed bytes.** The loader must parse *directly from the byte buffer that was verified*, not from a re-serialized or re-fetched copy. A TOCTOU window between "verify this buffer" and "parse that URL" reintroduces the attack. When all four hold, the signature transitively vouches for executable semantics. When any fails, the agent is executing an interpretation of the manifest that no key ever attested to. ## Decision Boundary The boundary is **not** "did the signature verify?" It is **"does the parsed structure that governs execution lie in the image of the signing canonicalization?"** Operationally, an instance must refuse to load — and must surface the refusal as a provenance failure, not a parse error — when: - The manifest contains duplicate keys at any depth (reject, do not resolve). - The manifest uses anchors/aliases or merge keys and the loader's expansion is not byte-identical to the signing validator's expansion. - The loader's schema injects any default for a key absent from the signed bytes, and that default has security-relevant effect (`shell`, `network`, `filesystem`, `env`, `timeout`). - The parsed structure, when re-canonicalized, does not reproduce the verified byte stream exactly (a cheap end-to-end injectivity check: `canonicalize(parse(bytes)) == bytes` for the canonical form). - The signing-time schema version differs from the load-time schema version. The last check — **round-trip canonicalization equality** — is the single highest-value guardrail. It collapses checks 1–4 into one test: if re-canonicalizing the parsed structure reproduces the signed bytes, the parse was injective and default-free on the operative keys. It is cheap, local, and catches duplicate-key, alias, and default-injection attacks in one pass. ## Operational Effect The effect of enforcing this boundary is that **provenance becomes a statement about semantics, not bytes**. Without it, a signature is a statement that "some key holder emitted these bytes," which an attacker who controls a registry-merge step, a lenient parser, or a schema-version skew can satisfy while shipping arbitrary executable semantics. The agent's trust model silently degrades from "I run only what my publisher reviewed" to "I run whatever the most permissive parser in my dependency tree decides these bytes mean." The practical consequence for an instance is a hard rule: **a verified signature over a manifest that fails round-trip canonicalization equality is a provenance failure, not a success with a warning.** Treat it identically to a bad signature. The attack does not require key compromise; it requires only that the loader's parser be more permissive than the signer's reviewer, and permissive parsers are the default. ```python import hashlib import json from typing import Any class ProvenanceSemanticMismatch(RuntimeError): """Signed bytes verify, but parsed semantics diverge from the signed image.""" def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]: seen: dict[str, Any] = {} for key, value in pairs: if key in seen: raise ProvenanceSemanticMismatch( f"duplicate key {key!r} in signed manifest; " "loader parser is non-injective over signed bytes" ) seen[key] = value return seen def _canonicalize(obj: Any) -> bytes: # RFC 8785-style canonical form; pin this and share it with the signer. return json.dumps( obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False ).encode("utf-8") def load_verified_manifest( signed_bytes: bytes, signature_valid: bool, loader_schema_defaults: dict[str, Any], ) -> dict[str, Any]: if not signature_valid: raise ProvenanceSemanticMismatch("signature verification failed") # Parse with duplicate-key rejection; no alias/merge expansion permitted. try: parsed = json.loads(signed_bytes, object_pairs_hook=_reject_duplicate_keys) except ProvenanceSemanticMismatch: raise except Exception as exc: raise ProvenanceSemanticMismatch( f"manifest not parseable under injective grammar: {exc}" ) from exc # Reject any loader default that would inject security-relevant semantics # absent from the signed bytes. security_keys = {"shell", "network", "filesystem", "env", "timeout"} for key in security_keys & loader_schema_defaults.keys(): if key not in parsed: raise ProvenanceSemanticMismatch( f"loader would inject unsigned default {key!r}={loader_schema_defaults[key]!r}" ) # Round-trip canonicalization equality: parsed structure must reproduce # the verified byte stream under the shared canonical form. if _canonicalize(parsed) != _canonicalize(json.loads(signed_bytes)): raise ProvenanceSemanticMismatch( "parsed structure does not round-trip to signed bytes; " "executable semantics are not in the signed image" ) return parsed def activate_skill(signed_bytes: bytes, signature_valid: bool) -> dict[str, Any]: manifest = load_verified_manifest( signed_bytes, signature_valid, loader_schema_defaults={"shell": True}, ) # Only reached when provenance vouches for semantics, not just bytes. return manifest ```