Skip to content

Cap client/hello nesting depth and size - #344

Merged
kahrendt merged 1 commit into
mainfrom
fix/client-hello-limits
Nov 4, 2026
Merged

kahrendt merged 1 commit into
mainfrom
fix/client-hello-limits

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

client/hello is the only message whose content a server can't know in advance. It can carry support objects for application-specific roles, and it arrives before any role is negotiated, so a server that doesn't implement such a role still has to parse its object. A server that parses JSON with a fixed nesting limit closes the connection on a deeply nested object, even though unknown fields must be ignored. No server can meet the "large enough that no valid message it can receive exceeds it" from #322 for client/hello either, since it has no maximum size. When the server initiated the connection and playback is running, it reconnects after a drop, so an oversized hello turns into a reconnect loop.

A client/hello now has at most 10 nesting levels and 16384 bytes, and servers must accept anything within those limits:

  • 10 levels, counting the root object as level 1. The deepest client/hello today is 5 levels, for example player@v1_support.supported_formats. 10 is also ArduinoJson's default limit, and it counts levels the same way.
  • 16384 bytes. A client/hello with every field at its maximum length and 82 formats is 6257 bytes. The formats cover 8 sample rates from 44.1 to 384 kHz, mono and stereo, every PCM and FLAC bit depth, and Opus. Only listing every channel count from 1 to 8 goes over, at 22223 bytes. A player over the cap drops its lowest priority formats.

I first looked at size caps for every JSON message and length caps for the metadata strings. I left them out, since every other message is either defined by the spec or only sent for roles both sides implement, so the spec already controls how large and how deep it gets. server/hello can't carry application-specific support objects, so it needs no cap.

sendspin-server-cpp already accepts both limits.

@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.

Good limit, thanks

@kahrendt
kahrendt merged commit 9881a37 into main Nov 4, 2026
1 check passed
@kahrendt
kahrendt deleted the fix/client-hello-limits branch November 4, 2026 15:52
kahrendt pushed a commit that referenced this pull request Nov 5, 2026
<!-- Describe the change and why it is needed. -->

A recognized message can carry a value outside its field's fixed range,
such as `output_delay_ms` above 5000 in `client/state` or a controller
`volume` of 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_max` or 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 a
`seek` outside 0 to `seek_max_ms`, a bad `client/init` is still an init
failure, and the #344 `client/hello` caps keep their MAY close.

This also removes handling the rule now covers:
- truncating an over-long server `name` or `group_name` (from #339) and
`client/pair-pending` `message` (from #194)
- the SHOULD close for an artwork `channels` array longer than 4
- the player clamp rules for `output_delay_ms` and `min_buffer_ms`,
since their 0-5000 field ranges already bind the sender

It also adjusts text the rule would otherwise break:
- an artwork client that truncates its `channels` array keeps at least
one entry
- metadata `track` states its range (at least 1), and `year` no longer
says "YYYY format"
- values inside ignored inactive-role objects are left unvalidated
- sending a value outside a range or length limit an earlier revision
defined needs negotiation, like a new field

So plain text over its byte cap now closes the connection too, including
a client `name` or `device_info` string over 64 bytes.

- [x] I accept the [Contributor License
Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this
contribution.
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