Skip to content

fix(signing): canonicalize signed/hashed JSON explicitly, not via serde_json map order - #2297

Merged
karajanchang merged 1 commit into
mainfrom
fix/canonical-json-signing
Nov 6, 2026
Merged

karajanchang merged 1 commit into
mainfrom
fix/canonical-json-signing

Conversation

@karajanchang

Copy link
Copy Markdown
Contributor

Why

Six sign/hash inputs build a json! object and serialize it with serde_json::to_vec, relying on serde_json::Map being a sorted BTreeMap. That only holds while nothing in the build enables serde_json/preserve_order. Cargo unifies features workspace-wide, so a single dependency turning it on switches every Map to insertion order and silently changes these bytes.

lancedb 0.41.0 does exactly that (serde_json ^1 ['preserve_order']; 0.37.1 had []). Trying the bump broke mur-channel::head_sign — existing channel signatures would stop verifying and HITL action_hash pins would drift. This PR removes the dependency on map order so the lancedb bump can land separately.

What

Route these through the existing mur_common::canonical::canonical_json (recursive key sort, no whitespace). Its output is byte-identical to the current output in a default build, so nothing already on disk changes:

Crate Site
mur-channel sign::sign_input, sign::sign_input_v2, Head::sign_input
mur-common hitl::pin::action_hash, signal sign input, memory proposal sign input
mur-agent-runtime Slack inbound bridge envelope payload

Doc comments that claimed "serde_json sorts object keys (no preserve_order)" are rewritten.

Not changed, on purpose:

  • Typed structs (OfficialLicense, fleet BundleManifest, conversation AuditAction) serialize in field declaration order, which preserve_order does not affect.
  • JCS callers (fleet_dispatch_request, git-broker action_hash, entitlements pin) already sort.
  • rotation.rs and the Telegram bridge each carry a private copy of the same canonicalizer; logic is identical to canonical.rs. Deduplicating is a follow-up, not a behavior change.

Tests

  • New golden-bytes test sign_input_bytes_are_key_sorted_at_every_depth (keys inserted out of order at two depths, v1 and v2).
  • cargo nextest run -p mur-channel -p mur-common: 1662 passed, default build.
  • Same with --features serde_json/preserve_order: 1662 passed.
  • Control: same preserve_order run without this change fails 2 (head_sign::sign_input_is_the_sorted_key_object_without_sig_or_ts, hitl::pin::tests::hash_is_stable_and_order_independent).
  • cargo clippy --all --all-targets --no-deps --locked -- -D warnings and cargo fmt --check clean; Slack/Telegram bridge tests pass.

Generated with MUR

…de_json map order

Six sign/hash inputs built a `json!` object and serialized it with
`serde_json::to_vec`, relying on `serde_json::Map` being a sorted BTreeMap.
That holds only while no crate in the build enables `serde_json/preserve_order`.
Cargo unifies features workspace-wide, so one dependency turning it on
(lancedb 0.41.0 does) silently switches every `Map` to insertion order and
changes these bytes: existing channel signatures stop verifying and HITL
action pins drift.

Route them through the existing `mur_common::canonical::canonical_json`
(recursive key sort, no whitespace), which is byte-identical to the
current output in a default build:

- mur-channel: event sign_input / sign_input_v2, Head::sign_input
- mur-common: hitl::pin::action_hash, signal sign_input, memory proposal
- mur-agent-runtime: Slack inbound bridge envelope payload

Typed structs (license, fleet bundle, audit action) serialize in field
declaration order and are unaffected; JCS callers already sort.

Adds a golden-bytes test for the channel sign input with keys inserted
out of order at two depths.

Verified: mur-channel + mur-common 1662 passed both default and with
`--features serde_json/preserve_order`; control run without this change
under preserve_order fails 2 (head_sign, hitl pin). CI clippy + fmt clean.
@karajanchang
karajanchang merged commit b68c10e into main Nov 6, 2026
15 checks passed
@karajanchang
karajanchang deleted the fix/canonical-json-signing branch November 6, 2026 00:54
karajanchang added a commit that referenced this pull request Nov 6, 2026
0.38-0.40 failed to compile without the `remote` feature
(lancedb/lancedb#4142); 0.41.0 fixes it (#4233), so move the exact pin.

lancedb 0.41 enables serde_json's `preserve_order`, which has two effects:

- Object key order now follows insertion order. Signing/hashing paths
  that relied on BTreeMap ordering were moved to canonical_json in the
  parent PR (#2297), so signed bytes are unchanged.
- `serde_json::Value` grows, pushing `TaskError` past clippy's
  `result_large_err` limit. Box `TaskError.details`; Box is transparent
  to serde, so the A2A wire format is unchanged (pinned by a new test).

lance no longer pulls tantivy transitively, so the tantivy pin comment
is updated: our direct use is now free to move independently.
karajanchang added a commit that referenced this pull request Nov 6, 2026
0.38-0.40 failed to compile without the `remote` feature
(lancedb/lancedb#4142); 0.41.0 fixes it (#4233), so move the exact pin.

lancedb 0.41 enables serde_json's `preserve_order`, which has two effects:

- Object key order now follows insertion order. Signing/hashing paths
  that relied on BTreeMap ordering were moved to canonical_json in the
  parent PR (#2297), so signed bytes are unchanged.
- `serde_json::Value` grows, pushing `TaskError` past clippy's
  `result_large_err` limit. Box `TaskError.details`; Box is transparent
  to serde, so the A2A wire format is unchanged (pinned by a new test).

lance no longer pulls tantivy transitively, so the tantivy pin comment
is updated: our direct use is now free to move independently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant