Skip to content

fix(ws): cap subscribeFiatRates tokens array length#1623

Merged
cranycrane merged 2 commits into
masterfrom
fix/ws-subscribe-fiat-rates-tokens-cap
Jul 13, 2026
Merged

fix(ws): cap subscribeFiatRates tokens array length#1623
cranycrane merged 2 commits into
masterfrom
fix/ws-subscribe-fiat-rates-tokens-cap

Conversation

@cranycrane

Copy link
Copy Markdown
Contributor

Summary

The subscribeFiatRates WebSocket handler accepted a tokens array of any length. It was the only list parameter in the WebSocket API without a bound — addresses (≤1000/100), currencies (≤128), timestamps (≤1000), and estimateFee blocks (≤32) are all capped.

The subscribed token list is retained for the lifetime of the connection and re-iterated on every fiat-rate broadcast (per subscribed currency) while the fiat-rates subscription lock is held, so leaving it unbounded lets a single request pin a large amount of memory and add avoidable work to each broadcast.

Change

  • Add maxWebsocketSubscribeFiatRatesTokens = 1000 and reject requests exceeding it with a public tokens max 1000 API error, before the list is stored — consistent with the existing caps on the other list parameters.
  • Add a regression test covering rejection at cap+1 and success at exactly the cap.

Testing

  • go test -tags unittest ./server/ -run Test_WebsocketFiatRates — passes.

🤖 Generated with Claude Code

cranycrane and others added 2 commits July 11, 2026 10:09
The subscribeFiatRates handler stored the request's tokens slice whole
for the connection lifetime and re-iterated it on every fiat-rate
broadcast (per subscribed currency) while holding the global
fiatRatesSubscriptionsLock. It was the only WebSocket list parameter
without a length cap: a single message up to the 4 MiB read limit could
carry ~10^6 token strings, enabling amplified heap retention and
periodic global-lock contention that stalls fiat-rate subscription
handling.

Reject requests whose tokens array exceeds
maxWebsocketSubscribeFiatRatesTokens (1000) with a public API error,
matching the existing caps on addresses, currencies, timestamps, and
estimateFee blocks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cranycrane cranycrane requested a review from pragmaxim July 13, 2026 06:22
@cranycrane cranycrane merged commit 5b82400 into master Jul 13, 2026
6 of 8 checks passed
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