8000 http-boundary: a bounded response read holds memory in proportion to its limit · Issue #415 · stratum-mining/sv2-ui · GitHub
[go: up one dir, main page]

Skip to content

http-boundary: a bounded response read holds memory in proportion to its limit #415

Open

Description

@GitGab19

Affected layers

  • Backend (server/): affected. readJsonWithLimit in server/src/bounded-json.ts counts the bytes it receives against a limit, but keeps every chunk the stream delivers as a separate object until the body ends. Each chunk costs a fixed overhead on top of its bytes, so a peer that sends its body in tiny pieces makes the read hold far more memory than its limit. It has two callers. fetchMonitoringJson in server/src/index.ts reads the monitoring APIs for the Telegram snapshot with a 1 MiB limit. The Telegram API client in server/src/telegram.ts uses a 4 MiB limit, but its peer is api.telegram.org over TLS, so the monitoring peer is the practical source.
  • Frontend (src/): not affected.
  • shared/: not affected.

Problem

The limit bounds the body's bytes, not the memory the read holds. Reproduced on main at ed7d84b with the Loupe test under Node 24: a valid JSON answer of 512 KiB, half the monitoring limit, delivered one byte per chunk, exhausts a 48 MiB heap. Over a real local connection, Loupe measured about 11 MiB retained for a 50 KB body sent as one-byte chunks within the 5-second deadline. How finely a real connection delivers a body depends on timing, so the amplification in practice is lower than the stream test's.

Impact

Whoever controls a monitoring peer, in practice a compromised mining container, can make each Telegram snapshot read hold many times its 1 MiB limit. Those reads run every few seconds while Telegram alerts are paired and enabled, with no browser open, and on a memory-constrained host they can exhaust the management process, which holds the Docker socket. The same attacker already has an unbounded path through the two monitoring proxies until #397 is fixed. Loupe rates it medium.

Expected outcome

  • The memory a bounded response read holds stays proportional to the bytes it accepted, plus a fixed allowance, however the peer splits the body into chunks.
  • Answers within the limit are parsed as today, and answers over it are rejected as today.

Loupe findings

  • project-loupe/audit-sv2-ui#114: the bounded JSON reader keeps one object per received chunk until the body ends

Related issues and PRs

Activity

  1. added
    area:http-boundary
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:http-boundary

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0