Skip to content

fix(id-core): canonical CBOR encoders accept values their decoders reject #11315

Closed

Description

@dezren39

Problem

The canonical CBOR encoders do not enforce the nesting-depth limit enforced by their decoders. Rust's encode_into recurses through arrays and map values without a depth parameter or guard (pkgs/id/crates/id-core/src/canonical_cbor.rs:132-179), while Reader::value_inner rejects depth greater than MAX_NESTING_DEPTH (64, :194-199, :270-273). The TypeScript mirror has the same mismatch: encodeInto recurses without a limit (pkgs/id/hosted-worker/src/canonical-cbor.ts:79-127), but Reader.valueInner rejects over-depth values (:184-185).

Consequently, a caller-built value with 65 nested arrays can be encoded successfully, but decoding those bytes returns TooDeeplyNested. Still deeper caller-built values recurse without a bound during encoding and can exhaust the stack. This breaks the encoder/decoder round-trip contract and leaves the producer path without the decoder's stack-safety bound.

Requested change

Apply the same depth policy to both encoders and return the existing typed TooDeeplyNested error when a value exceeds it. Add Rust and TypeScript tests for the boundary and over-limit nesting, including parity between the implementations.

Related work

Closed #2121 addresses unbounded nesting in a different ID tuple decoder. It does not cover these canonical CBOR encoders. No open issue or PR specifically tracking this encoder/decoder mismatch was found in the dedupe search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions