Skip to content

Cap client-sent text fields in UTF-8 bytes - #329

Merged
kahrendt merged 2 commits into
mainfrom
fix/client-hello-text-limits
Oct 21, 2026
Merged

kahrendt merged 2 commits into
mainfrom
fix/client-hello-text-limits

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

Any device on the network can put text of any length into name and the device_info strings in client/hello without pairing, and the server shows it to the operator in its device list.

This caps each of them at 64 bytes in UTF-8, so a server can reject a client that sends more. I picked 64 bytes since Matter caps its version strings at 64 UTF-8 bytes, and UPnP recommends friendly and manufacturer names under 64 characters.

client/pair-pending message was capped at 200 characters with no unit, so a client and a server that count differently could disagree on a non-ASCII message. It now counts 200 bytes in UTF-8 as well.

@kahrendt kahrendt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kahrendt
kahrendt merged commit 7f23b6c into main Oct 21, 2026
1 check passed
@kahrendt
kahrendt deleted the fix/client-hello-text-limits branch October 21, 2026 11:54
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Nov 2, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

Fixes several server-side pairing edge cases.

- Lenient servers now also refuse a pairing method that `client/hello`
didn't list, before sending the activation. Before, they sent it and let
the client abort. A client that offered both pairing code methods can
still pair with the static code, now also on strict servers.
- Retrying pairing no longer fails right away when a late `pair/abort`
with `attempt_timeout` or `pairing_code_mismatch` from the previous
attempt arrives.
- The `client/pair-pending` message is now capped at 200 bytes in UTF-8
instead of 200 characters.
- A pairing frame with no pairing `server/activate` since the handshake,
an explicit null for `locations`, and a `pairing_index` below 1 are now
flagged as noncompliant.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#329

## 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`
maximmaxim345 pushed a commit that referenced this pull request Nov 3, 2026
<!-- Describe the change and why it is needed. -->

#329 capped the text fields a client sends in `client/hello`. The server
sends two friendly names that the client stores and shows: `name` in
`server/hello` and `group_name` in `group/update`. Neither has a length
limit.

This caps both at 64 bytes in UTF-8, so a client can hold them in fixed
storage instead of an allocation whose size the server controls. 64
bytes matches the client-side caps from #329, which follow Matter's
64-byte version strings and UPnP's friendly-name guidance. The cap
counts bytes, not characters, so both sides count the same way.

A client that receives a longer value truncates it at a UTF-8 character
boundary instead of closing the connection. The server would send the
same name again on every reconnect, so closing would leave the client
disconnecting over and over, with nothing to show the user that a name
is the cause. A `group_name` the server didn't check would disconnect
every client in the group. This matches the `client/pair-pending`
`message`, the one other display string with a cap, where the receiver
truncates.

The server's mDNS TXT `name` is not capped, matching #329's handling of
the client's TXT `name`. It SHOULD match the `server/hello` `name` and
is only a discovery hint.

- [x] I accept the [Contributor License
Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this
contribution.
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Nov 5, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

The client SDK counted `PairingSupport.pair_pending_message` in
characters, but the spec caps the `client/pair-pending` message at 200
bytes in UTF-8. So a non-ASCII message could pass the SDK check and then
be cut off or refused by the server.

`PairingSupport` now raises `ValueError` for a message over 200 bytes in
UTF-8, which is stricter than before for non-ASCII text.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#329

## 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`
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`
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.

2 participants