Skip to content

fix(net): read an IETF request message's body before allocating it - #9250

Merged
kixelated merged 1 commit into
mainfrom
fix/ietf-request-stream-prealloc
Nov 21, 2026
Merged

kixelated merged 1 commit into
mainfrom
fix/ietf-request-stream-prealloc

Conversation

@kixelated

@kixelated kixelated commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

RequestStream.#readFramed (js/net/src/ietf/request_stream.ts) allocated 2 + size bytes from a peer-declared u16 length before any body bytes arrived. A peer could send a 3-byte header declaring a 64 KiB message and withhold the body. Each stream then held a 64 KiB buffer, about 21,000x the bytes the peer sent (GHSA-pr4h-3fvv-mfgm, reported by Rikuxx0).

Only main is affected: the code isn't on release, and the published @moq/net (0.4.8) predates it.

Approach

Read the body first and allocate the framed copy after it arrives. Reader.read(size) already collects the chunks as they come in, so a peer that withholds the body holds only what it actually sent, within QUIC flow control.

I checked the other length-prefixed reads in js/net (lite and IETF message decode, parameters, setup options, auth) and the streamed frame payloads. They all read before allocating or stream by segment. The Rust request_stream.rs doesn't allocate from a declared size up front.

Impact

  • No public API or wire change.

Validation

  • Ran the reporter's PoC (100 request streams, each sending 0x02 0xff 0xff):
    • before: 6,553,700 bytes allocated for 300 received.
    • after: 0 bytes allocated.
  • bun test src/ietf/ (659 pass) and just check pass.
  • No unit test added: allocation can only be observed by proxying the global Uint8Array, and this is an old-bug regression rather than an edge case.

Caused by

  • moq-dev/moq#6130 - its new #readFramed sized the framed buffer from the declared length before reading the body (found by person; GHSA-pr4h-3fvv-mfgm)

Alternatives

  • Cap the pending body memory per session or add a body-read deadline. Not needed once nothing is allocated before the bytes arrive; QUIC flow control already bounds the bytes a peer can make us buffer.

Follow-ups

None.

Models

Size: XS
Implementer: Claude Code, claude-opus-5-5, unknown effort

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: e33e1fa

  • Base: origin/main at 037c6f1

  • Risk: medium, This changes shipped request-stream buffering behavior and could affect JS clients handling delayed peer messages, while preserving the API and wire format; a revert fully undoes it.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a1fa83-90ca-7113-8e60-47d050516e97

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1fb9a-5c02-7673-8f50-1cacdd95ffa0, round 1

  • Score: 10/10, The minimal fix defers allocation until the body arrives without changing framing or error handling, with no regressions identified by source inspection; tests were not run.

  • Rounds: 2; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

A peer could declare a 64 KiB request stream message, withhold the body,
and make us hold a 64 KiB buffer for every 3 bytes it sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b0cef5b-7835-4ae5-8d96-fdefa6f351b1
Commits

Reviewing files that changed from the base of the PR and between 2170d06 and e33e1fa.

Files selected for processing: 1

  • js/net/src/ietf/request_stream.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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

✅ No new issues found.

Approach: sound. Reader.read(size) collects chunks as they arrive, so moving the new Uint8Array(2 + size) allocation after the body read means a peer that withholds the body holds only the bytes it actually sent.

Reviewed changes

  • #readFramed allocation order (js/net/src/ietf/request_stream.ts): reads the body before allocating the framed buffer. The framing and the error path (malformed(...)) are unchanged.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 444a1c5 Nov 21, 2026
7 checks passed
@kixelated
kixelated deleted the fix/ietf-request-stream-prealloc branch November 21, 2026 01:41
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.

1 participant