Repository navigation
Bound logged peer text and reject a non-array active_roles - #244
Merged
Merged
Conversation
- PEER_TEXT_LOG_BYTES and peer_text_for_log() move to inline_text.h and bound every log of peer text no field bounds: the unhandled message type, an unrecognized enum value (server/activate's pairing method and format) and the pair/abort reason, each reachable after the handshake from a connection keyed with the Sentinel PSK. - determine_message_type() reads type as a string_view, so a type with an embedded NUL no longer matches a known one. - A present server/activate active_roles that is not an array logs and rejects the activate, like stream/end and stream/clear roles; null still keeps the prior set. - conventions.md says unbounded peer text is logged only up to the cap.
It shared 19105 with the stream-roles test, so a parallel ctest run failed whichever bound second.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unbounded group IDs are still printed in debug logs, contradicting the documented logging guarantee and requiring either bounded output or an explicit exception.
3 open issues
What changed in this PR
This PR hardens the library’s protocol handling by bounding peer text in logs, matching complete message types, and rejecting malformed activation data.
Changes:
- Shares a UTF-8-safe, 32-byte logging cap across handshake, parser, and dispatch paths.
- Rejects message types containing extra bytes and non-array
active_roles, while preserving absent/null behavior. - Adds regression coverage, documents the logging bound, and resolves a lifecycle-test port collision.
| File | Description |
|---|---|
tests/test_protocol.cpp |
Tests embedded null bytes, active_roles validation, and parser log bounds. |
tests/test_encrypted_lifecycle.cpp |
Tests the log bound for unhandled message types. |
tests/test_client_lifecycle.cpp |
Assigns the inbound-disabled test a separate port. |
src/protocol.cpp |
Bounds peer-value logs, compares complete types, and validates active_roles. |
src/noise_handshake.cpp |
Uses the shared truncation helper for handshake logs. |
src/inline_text.h |
Defines the shared logging cap and truncation helper. |
src/connection_manager.cpp |
Updates comment wording about unrecognized pairing-method logging. |
src/client_dispatch.cpp |
Bounds unhandled message-type logs. |
docs/conventions.md |
Documents the peer-text logging limit. |
Review effort: Max
- The main loop's group/update debug log cuts group_id to PEER_TEXT_LOG_BYTES; group_name is already cut at parse. - NoiseHandshakeDriver.UnexpectedPeerTextIsLoggedOnlyUpToTheBound covers the handshake's two log sites, the unexpected type and the server/error reason. - The pairing-index bump comment says a server/activate the parser rejects is not counted.
This was referenced Nov 4, 2026
kahrendt
added a commit
that referenced
this pull request
Nov 4, 2026
## Summary A follow-up from #244. messaging.md "server/activate" requires a client to close with `client/goodbye` reason `'unauthorized'` when `active_roles` is non-empty on a connection that is not playback-capable. `process_server_activate_message()` skipped a non-string entry, so `active_roles:[7]` read as empty and such a connection was admitted where a strict client closes. ## Change - **active_roles:** a non-string entry goes to `ActiveRoles::add()` as an empty name. It sets no role bit but makes the set non-empty, like a role version this library does not implement, so the existing admission check closes the connection with `'unauthorized'`. A `null` entry reads the same way. - **Siblings unchanged:** `activities` and `stream/end`/`stream/clear` `roles` keep skipping such entries, since there one only narrows what the message applies to; a comment at the `active_roles` site says why it differs. ## Tests - `Protocol.ServerActivateReadsActiveRoles`: the `[7]` row expects a non-empty set with mask 0; restoring the skip fails it. Admission takes only whether the set is empty, which `Admissible.RolesRequirePlaybackCapability` already covers both ways, so no admission test changes.
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.


Summary
From the second coherence pass on the allocation follow-ups (Sendspin/backlog#92). The handshake logs peer text only up to 32 bytes, but after it three sites a connection keyed with the published Sentinel PSK reaches logged peer text at full length: up to 16 KiB per message, enough to stall the protocol task on a UART console.
determine_message_type()also comparedtypeas aconst char*, so a type with an embedded NUL ("server/hello\u0000x") dispatched as the known one. Separately, a present non-arrayserver/activateactive_roleswas silently taken as omitted, keeping the prior roles, while its siblingstream/*rolesrejects.Change
PEER_TEXT_LOG_BYTES(32) andpeer_text_for_log()(a UTF-8-safe cut) move fromnoise_handshake.cpptoinline_text.h. They bound the unhandled messagetype, an unrecognized enum value fromread_enum_field()(server/activate'spairing.method/pairing.format), and thepair/abortreason. Every other peer string is bounded where it is parsed.determine_message_type()readstypeonce as astring_viewand compares with==.read_stream_roles(); absent or null still keeps the prior set. A rejected activate leaves a nursery connection to the 30 s establish reap and an admitted one with its prior state.conventions.mdsays peer text no field bounds is logged only up to the cap.Tests
Protocol.DetermineMessageTypegains an embedded-NUL row; astrcmpcomparison fails it.Protocol.ServerActivateReadsActiveRolesgains null, string and object rows; restoring the nullopt fallback fails the string and object rows, dropping the null branch fails the null row.Protocol.UnrecognizedPeerTextIsLoggedOnlyUpToTheBound(pairing method and pair/abort reason) andEncryptedLifecycle.AnUnhandledTypeIsLoggedOnlyUpToTheBoundcapture stderr and check 32 bytes are logged and 33 are not; dropping each cut fails its test.Not in this PR
activities,active_rolesorstream/*rolesis still skipped, soactive_roles:[7]on a connection that is not playback-capable passes the "MUST be empty" rule.