fix(core): normalise raw-socket bytes to Uint8Array before CBOR decode - #88
Merged
Conversation
createTcpTransport and createTlsTransport fed decode() a Buffer sliced straight off the accumulator, so cbor2 sliced nested byte-string values as Buffer too. Its own encode() doesn't recognise a Buffer as a byte string and silently serialises it as a generic object instead, so any later re-encode of a decoded byte string produces the wrong bytes. A capability token's signature verification does exactly that re-encode (COSE's Sig_structure, built from the token's own protected-header and payload byte strings), so every capability token received over a real TCP/TLS connection failed signature verification despite the token's bytes crossing the wire perfectly intact. Wrapping the socket's body in a plain Uint8Array view before decode -- the same normalisation frame-codec.ts already applies for its own message-based transports -- avoids the whole class of bug.
Mearman
force-pushed
the
fix/cbor-buffer-decode-reencode
branch
from
September 12, 2026 08:31
851ae64 to
6a66123
Compare
Mearman
marked this pull request as ready for review
September 12, 2026 08:32
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Sep 12, 2026
Mearman
added a commit
to ExaDev/agent-comms
that referenced
this pull request
Sep 12, 2026
Every capability token received over a genuine TCP/TLS connection failed signature verification despite its bytes crossing the wire perfectly intact -- a cbor2 Buffer-vs-Uint8Array mismatch, fixed upstream in ExaDev/wire-mesh#88. This dependency's own project-level .npmrc gains a matching minimum-release-age exclusion, since it's a first-party package this repo depends on.
Mearman
added a commit
to ExaDev/agent-comms
that referenced
this pull request
Sep 12, 2026
Every capability token received over a genuine TCP/TLS connection failed signature verification despite its bytes crossing the wire perfectly intact -- a cbor2 Buffer-vs-Uint8Array mismatch, fixed upstream in ExaDev/wire-mesh#88. This dependency's own project-level .npmrc gains a matching minimum-release-age exclusion, since it's a first-party package this repo depends on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #89.
createTcpTransport and createTlsTransport's own frame readers slice the raw accumulator Buffer directly and hand that slice to cbor2's decode() as-is. cbor2 mirrors the input's own class for nested byte-string values, so a Buffer input produces Buffer-typed byte strings in the decoded structure rather than plain Uint8Array. cbor2's encode() then doesn't recognise a Buffer as a byte string at all -- it falls through to serialising it as a generic object -- so any later re-encode of a decoded byte string silently produces the wrong bytes.
A capability token's own signature verification does exactly that re-encode: COSE's Sig_structure is built by re-encoding the token's own protected-header and payload byte strings. Any capability token received over a real TCP or TLS connection therefore failed signature verification with
bad_signature, despite the token's bytes crossing the wire perfectly intact -- confirmed by tracing the exact byte arrays on both ends and finding them identical, then finding the corruption only appeared once the received bytes were re-encoded.Fix: wrap the socket's extracted body in a plain Uint8Array view (same range, same backing memory, just a class cbor2's encoder actually recognises) before calling decode(), matching frame-codec.ts's own existing
new Uint8Array(data)normalisation for its message-based transports.Added a regression test (
tcp-transport-token-bytes.test.ts) that sends a manage-request frame carrying a multi-field byte-string token over a real TCP connection and asserts that re-encoding a received byte string reproduces the pre-send bytes exactly -- the actual property that was broken. Confirmed RED against the pre-fix code and GREEN after.Full core test suite (160 tests) and the wider ts workspace build/lint/test all pass.