Repository navigation
Close the connection on out-of-range values - #347
Merged
Merged
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
# Conflicts: # README.md # messaging.md
maximmaxim345
marked this pull request as ready for review
November 4, 2026 19:08
kahrendt
reviewed
Nov 5, 2026
kahrendt
left a comment
Contributor
There was a problem hiding this comment.
This is probably better suited for a follow-up PR, but the visualizer and source roles still both have "protocol error, SHOULD close" type of arrangement. Since we are getting strict about checks here we probably want to make those close the connection as well.
Member
Author
Sounds good, opened a follow-up PR for that: |
1 task done
kahrendt
pushed a commit
that referenced
this pull request
Nov 5, 2026
<!-- Describe the change and why it is needed. --> Two role rules call a message a protocol error but only say the server SHOULD close the connection: a visualizer `client/state` that requests `'spectrum'` without a `spectrum` object, and a source `client-stream/start` without a matching server `start`. Every other per-role protocol error requires closing. This makes both a MUST. A client that follows the spec can't send either one, since the `spectrum` object is required and the source rules already tolerate a `client-stream/start` that crosses a `stop`, a role removal or an availability update. Keeping the connection open didn't help for the source case anyway, since the first audio chunk on a stream the server never opened already requires closing. The artwork `channels` SHOULD close is left to #347, which removes it. Related: - #347 ## Breaking changes Servers only: a server that kept the connection open on either message now closes it. Clients don't need to change. - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
1 task done
maximmaxim345
pushed a commit
that referenced
this pull request
Nov 9, 2026
<!-- Describe the change and why it is needed. --> `group_id` in `group/update` is a string of any length and content. The client keeps it to tell when its group changes, so the server decides how much the client has to store. This gives it the same format as the spec's other identifiers (`client_id`, `server_id`, `psk_id`): 32 bytes, base64url-encoded without padding, 43 characters. A client can hold it in fixed storage, and since the value is ASCII, bytes and characters are the same count. The server chooses the 32 bytes. A server with existing IDs, such as UUIDs or database keys, can use a SHA-256 hash of its own ID, which stays the same for the life of the group. A value in any other format can only come from a server bug, so it is a protocol error and the client MUST close the connection, as it does for other out-of-range values (#347). That rule covers only the length, so `group_id` states its own rule to also cover a 43-character value with characters outside base64url, which could take more than 43 bytes. ## Breaking changes - Servers: must send `group_id` as 32 bytes, base64url-encoded without padding. A server that sends another format, like a UUID, will have updated clients close the connection. - Clients: must close the connection on a `group_id` that is not 43 base64url characters. A client that doesn't check keeps working with any server that follows the spec. - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
This was referenced Nov 10, 2026
Merged
kahrendt
added a commit
to Sendspin/sendspin-cpp
that referenced
this pull request
Nov 10, 2026
…p_id (#256) ## Summary `group/update` still copied `group_id` and `group_name` onto the heap through `operator new`, which aborts on ESPHome. Both fields are now held inline from the parse to the main loop, and the public strings are filled in place, so a `group/update` allocates nothing. Part of Sendspin/backlog#92. The change also adopts Sendspin/spec#340: `group_id` must be 43 base64url characters, and anything else is a protocol error that closes the connection. Servers in use today, aiosendspin among them, still send 36-character UUIDs, so enforcement is staged. `GROUP_ID_STRICT` (in `protocol.cpp`) stays `false` for now. **Behaviour change:** a non-conforming `group_id` now reaches consumers as `base64url(SHA-256(id))` instead of as sent, with one warning per connection. Setting the flag to `true` makes a `group/update` whose `group_id` is absent or not in that format close the connection. ## Change - **Parse:** the protocol task decodes the fields into a private, trivially copyable `GroupUpdatePayload` (`IdText`, `ServerName`) carried through the inbox slot. `group_id_from_wire()` handles every case: kept, normalized, rejected, ignored, and null or non-string values. - **Main loop:** `GroupUpdateObject`'s `std::optional<std::string>` fields, in both the group state and the delta `on_group_update()` receives, are filled through `ReservedText` (`src/reserved_text.h`). It keeps a string reserved for the field's bound when the client is built and swaps it in and out rather than freeing it on a clear. The metadata role can reuse it once metadata strings have a spec cap. - **Normalization:** hashing a non-conforming id costs one noise-c `calloc` per normalized id (noted in internals.md "Memory"). When that allocation fails, the connection is closed rather than applying the rest of the update under the previous group's id. ## Tests - `Protocol.GroupIdIsKeptNormalizedOrRejected`: a table covering lenient and strict outcomes, with hashes checked against openssl. Rows: a conforming control, a UUID, 44 characters, a standard-alphabet `+`, empty, null, a number, absent. - `EncryptedLifecycle.GroupIdReachesTheListenerAsSentOrNormalized`: an end-to-end check of what the listener's delta and the group state show. - Gap: the close on a failed normalization cannot be driven without a production seam (noise-c's `calloc` inside a local `Sha256`). - New alloc window for the first `group/update` messages (normalize, clear the name, set a new name), expected 0. `RestartYieldsALiveClient` now checks that the group fields clear. - Follow-ups when the flag flips: an end-to-end strict-close test, closing on an over-long `group_name` per Sendspin/spec#347, and whether an absent `playback_state` or `group_name` closes it too. Stack (ESP-IDF 5.5.4, esp32): every task matches `tools/stack_usage/README.md`, the protocol task at 6,544 B -Os / 6,688 B -Og against its 7,168 B default.
maximmaxim345
pushed a commit
that referenced
this pull request
Nov 11, 2026
The `metadata` string fields have no length limit, so a constrained client can't size its buffers ahead of time and has to allocate on the heap at runtime. This caps `title`, `artist`, `album_artist` and `album` at 255 bytes in UTF-8, and `artwork_url` at 2048 bytes. 255 bytes is too short for some artwork URLs, such as image-proxy URLs that wrap a percent-encoded source URL, or signed CDN URLs. A value over its cap falls under the out-of-range rule from #347, so the client closes the connection. I'm not entirely sure if 2048 bytes is a good limit for the artwork URL. It is definitely on the safe side, but it does take more space than all the other fields combined. It's not a big deal in general, though, because a memory conscious client could be careful about this and pre-register which fields they want and discard the rest, so, for example, ESPHome could just say I want title and it would only reserve 255 bytes ahead of time and everything else in metadata is thrown away (this is not a spec idea, this is just a library implementation detail). Closes #341 - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
1 of 9 tasks
maximmaxim345
added a commit
to Sendspin/aiosendspin
that referenced
this pull request
Nov 17, 2026
# What does this implement/fix? <!-- Quick description and explanation of changes. --> Clients that follow the spec close the connection when the server/hello `name` or the group/update `group_name` is longer than 64 bytes in UTF-8. A long or non-Latin server name therefore made them reconnect in a loop. The server now cuts both names to 64 bytes without splitting a character. It cuts the mDNS `name` the same way. `SendspinServer.name` and `SendspinGroup.group_name` still return the full name. **Related issue or spec PR (if applicable):** - Sendspin/spec#339 - Sendspin/spec#347 ## Types of changes <!-- Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the matching label, and the release notes use it to sort this change. --> - [x] Bugfix (non-breaking change which fixes an issue): `bugfix` - [ ] New feature (non-breaking change which adds functionality): `new-feature` - [ ] Enhancement to an existing feature: `enhancement` - [ ] Breaking change (changes the public API or the protocol in a way that is not backwards compatible): `breaking-change` - [ ] Refactor (no behavior change): `refactor` - [ ] Documentation only: `documentation` - [ ] Maintenance / chore: `maintenance` - [ ] CI / workflow change: `ci` - [ ] Dependencies bump: `dependencies`
1 of 9 tasks
maximmaxim345
added a commit
to Sendspin/aiosendspin
that referenced
this pull request
Nov 17, 2026
…624) # What does this implement/fix? <!-- Quick description and explanation of changes. --> The client SDK could send a `client/hello` name or `device_info` string over 64 UTF-8 bytes, or a `min_buffer_ms` up to 30000. Conforming servers close the connection on these, and an aiosendspin server in strict mode rejects the client. The client now cuts those strings to 64 bytes without splitting a character, and clamps `min_buffer_ms` to 0-5000. **Related issue or spec PR (if applicable):** - Sendspin/spec#313 - Sendspin/spec#329 - Sendspin/spec#347 ## Types of changes <!-- Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the matching label, and the release notes use it to sort this change. --> - [x] Bugfix (non-breaking change which fixes an issue): `bugfix` - [ ] New feature (non-breaking change which adds functionality): `new-feature` - [ ] Enhancement to an existing feature: `enhancement` - [ ] Breaking change (changes the public API or the protocol in a way that is not backwards compatible): `breaking-change` - [ ] Refactor (no behavior change): `refactor` - [ ] Documentation only: `documentation` - [ ] Maintenance / chore: `maintenance` - [ ] CI / workflow change: `ci` - [ ] Dependencies bump: `dependencies`
53 of 58 tasks
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.
A recognized message can carry a value outside its field's fixed range, such as
output_delay_msabove 5000 inclient/stateor a controllervolumeof 101. Most fields don't say what the receiver does with one.This makes such a value a protocol error, and the receiver MUST close the connection. Only a broken implementation sends one, and closing matches how the spec treats other protocol errors. The rule only covers fixed ranges and length limits. Bounds relative to another value, like the visualizer
rate_maxor the player timing bounds, can be crossed by a message in flight, and the receiver often can't check them reliably. A field or message with its own rule keeps it: the server still ignores aseekoutside 0 toseek_max_ms, a badclient/initis still an init failure, and the #344client/hellocaps keep their MAY close.This also removes handling the rule now covers:
nameorgroup_name(from Cap server-sent friendly names in UTF-8 bytes #339) andclient/pair-pendingmessage(from Rework pairing attempt gating #194)channelsarray longer than 4output_delay_msandmin_buffer_ms, since their 0-5000 field ranges already bind the senderIt also adjusts text the rule would otherwise break:
channelsarray keeps at least one entrytrackstates its range (at least 1), andyearno longer says "YYYY format"So plain text over its byte cap now closes the connection too, including a client
nameordevice_infostring over 64 bytes.