Skip to content

fix(http3): bound connect-udp datagram events per control stream read - #4182

Draft
larseggert wants to merge 1 commit into
mainfrom
fix-ANT-2026-76JLDZJA
Draft

larseggert wants to merge 1 commit into
mainfrom
fix-ANT-2026-76JLDZJA

Conversation

@larseggert

@larseggert larseggert commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

A connect-udp session turned every DATAGRAM capsule readable on its control stream into an event in a single read, so a peer could make the receiver queue one event per few bytes of a whole flow-control window. Each read now charges every datagram its payload size plus 64 bytes of overhead against a 256 KiB budget and drops datagrams beyond it, as RFC 9298 Section 5 and RFC 9221 Section 5.3 allow. Parsing continues, so the stream is still consumed and the session stays usable. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-76JLDZJA.

Also reported independently by @gadievron, as H3Q-037.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 05:45

Copilot AI 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.

🟢 Approval recommended

Static review found no blocking defects in the bounded accounting, continued parsing, or regression tests; tests were not executed.

No open issues 🎉

What changed in this PR

This PR limits CONNECT-UDP datagram events generated by a single control-stream read, reducing memory amplification while continuing to consume the stream.

Changes:

  • Adds a 256 KiB per-read budget, charging each datagram’s payload size plus 64 bytes of overhead.
  • Drops datagrams that exceed the remaining budget without stopping capsule parsing.
  • Adds regression tests for both directions, budget boundaries, and subsequent datagram delivery.
File Description
neqo-http3/​src/​features/​extended_connect/​tests/​webtransport/​mod.rs Exposes the connection helper for reuse in CONNECT-UDP tests.
neqo-http3/​src/​features/​extended_connect/​tests/​mod.rs Makes the WebTransport test module accessible to sibling tests.
neqo-http3/​src/​features/​extended_connect/​connect_udp_session.rs Enforces the per-read event budget and adds regression tests.

Review effort: Balanced

@github-actions github-actions 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 findings.

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.13043% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.80%. Comparing base (3f539e1) to head (20f6f35).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4182      +/-   ##
==========================================
- Coverage   96.97%   96.80%   -0.17%     
==========================================
  Files         113      118       +5     
  Lines       42253    42711     +458     
  Branches    42253    42711     +458     
==========================================
+ Hits        40976    41348     +372     
- Misses       1263     1339      +76     
- Partials       14       24      +10     
Flag Coverage Δ
freebsd 94.72% <99.13%> (-0.12%) ⬇️
linux 97.01% <99.13%> (-0.03%) ⬇️
macos 95.13% <99.13%> (-0.03%) ⬇️
windows 95.22% <99.13%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
neqo-common 99.32% <100.00%> (ø)
neqo-http3 95.66% <99.13%> (+0.04%) ⬆️
neqo-qpack 96.71% <ø> (ø)
neqo-transport 97.63% <100.00%> (-0.06%) ⬇️
neqo-udp 90.03% <ø> (ø)
mtu 89.13% <ø> (ø)

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 2.8%

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 8 improved benchmarks
✅ 93 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Walltime walltime/pacing-true/same-seed 4.5 ms 4.4 ms +3.91%
⚡ Walltime walltime/pacing-true/varying-seeds 4.7 ms 4.5 ms +3.7%
⚡ Walltime walltime/pacing-false/same-seed 4 ms 3.8 ms +3.02%
⚡ CPU Simulation simulated/pacing-false/varying-seeds 70.6 ms 68.8 ms +2.75%
⚡ Walltime 1-conn/10_000-parallel-1b-resp (aka. RPS) 81.6 ms 79.5 ms +2.69%
⚡ Walltime walltime/10-streams/each-1048576-bytes 35.1 ms 34.4 ms +2.13%
⚡ Walltime walltime/1000-streams/each-1000-bytes 15.4 ms 15.1 ms +2.12%
⚡ Walltime walltime/1-streams/each-4194304-bytes 13 ms 12.8 ms +2.1%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix-ANT-2026-76JLDZJA (20f6f35) with main (db74969)

Open in CodSpeed

@larseggert larseggert added p2 Issues that we want to fix client-side Issue relates more to clients extended-connect WebTransport, CONNECT, connect-udp, HTTP datagrams labels Oct 27, 2026
@larseggert
larseggert force-pushed the fix-ANT-2026-76JLDZJA branch from 5932039 to 74929eb Compare October 28, 2026 14:01

@github-actions github-actions 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 findings.

Drop datagram capsules once one read of the control stream has queued 256 KiB of datagram events, so a peer cannot make the receiver queue an event per tiny capsule across a whole flow-control window.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-76JLDZJA.
@larseggert
larseggert force-pushed the fix-ANT-2026-76JLDZJA branch from 74929eb to 20f6f35 Compare October 28, 2026 14:43

@github-actions github-actions 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 findings.

@github-actions

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server, differences relative to main at db74969.

neqo-pr as clientneqo-pr as server
neqo-pr vs. go-x-net: BP BA
neqo-pr vs. haproxy: BP BA
neqo-pr vs. kwik: 🚀DC Z ⚠️R 3 L1 C1 🚀6 BP BA
neqo-pr vs. linuxquic: run cancelled after 20 min
neqo-pr vs. lsquic: L1 C1
neqo-pr vs. msquic: A L1 C1
neqo-pr vs. mvfst: A
neqo-pr vs. neqo: 🚀Z A
neqo-pr vs. nginx: 🚀C1 BP BA
neqo-pr vs. ngtcp2: Z 🚀C1 CM
neqo-pr vs. picoquic: A BP ⚠️BA
neqo-pr vs. quic-go: A
neqo-pr vs. quiche: BP BA
neqo-pr vs. s2n-quic: CM
neqo-pr vs. tquic: S BP BA
neqo-pr vs. xquic: S R Z A L1 C1 BA
go-x-net vs. neqo-pr: CM
kwik vs. neqo-pr: BP BA CM
linuxquic vs. neqo-pr: run cancelled after 20 min
lsquic vs. neqo-pr: ⚠️C1
msquic vs. neqo-pr: CM
mvfst vs. neqo-pr: Z L1 C1 CM
neqo vs. neqo-pr: run cancelled after 20 min
openssl vs. neqo-pr: LR M A CM
quic-go vs. neqo-pr: CM
quic-zig vs. neqo-pr: baseline result missing
quiche vs. neqo-pr: 🚀L1 CM
quinn vs. neqo-pr: 🚀C1 ⚠️L1 V2 CM
s2n-quic vs. neqo-pr: CM
tquic vs. neqo-pr: CM
xquic vs. neqo-pr: M CM
All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

@github-actions

Copy link
Copy Markdown
Contributor

Client/server transfer results

Performance differences relative to db74969.

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server Mean±σ Min–Max Median±MAD MiB/s±σ ΔMedian
google-neqo-cubic 80.5 ± 0.5 79.4 – 81.7 80.4 ± 0.6 397.6 ± 2.4 💔 +0.9 (+1.1%)

Table above only shows statistically significant changes. See all results below.

All results

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server Mean±σ Min–Max Median±MAD MiB/s±σ ΔMedian
google-google 155.3 ± 0.6 153.9 – 156.8 155.3 ± 0.6 206.0 ± 0.8
google-neqo-cubic 80.5 ± 0.5 79.4 – 81.7 80.4 ± 0.6 397.6 ± 2.4 💔 +0.9 (+1.1%)
neqo-google-cubic 249.3 ± 41.2 198.8 – 329.2 250.5 ± 63.6 128.4 ± 21.2 +42.7 (+20.5%)
neqo-neqo-cubic 23.1 ± 0.2 22.6 – 23.8 23.1 ± 0.1 1386.6 ± 11.8 +0.1 (+0.3%)
neqo-neqo-cubic-nopacing 22.6 ± 0.2 22.0 – 23.2 22.6 ± 0.2 1417.7 ± 13.3 -0.0 (-0.1%)
neqo-neqo-newreno 23.0 ± 0.2 22.6 – 23.5 23.0 ± 0.2 1392.2 ± 10.7 +0.1 (+0.6%)
neqo-neqo-newreno-nopacing 22.6 ± 0.2 22.2 – 23.1 22.6 ± 0.1 1416.2 ± 10.9 -0.0 (-0.1%)
neqo-quiche-cubic 34.8 ± 0.4 33.8 – 35.9 34.8 ± 0.5 918.6 ± 11.2 +0.1 (+0.2%)
neqo-s2n-cubic 45.6 ± 0.2 45.0 – 46.2 45.7 ± 0.2 701.4 ± 3.7 +0.0 (+0.1%)
quiche-neqo-cubic 37.1 ± 1.1 35.2 – 39.8 37.2 ± 1.4 861.7 ± 25.6 -0.2 (-0.6%)
quiche-quiche 41.3 ± 0.3 40.7 – 42.0 41.4 ± 0.3 774.6 ± 5.0
s2n-neqo-cubic 127.5 ± 1.0 125.8 – 132.3 127.5 ± 0.9 250.9 ± 1.9 +0.6 (+0.4%)
s2n-s2n ⚠️ 177.1 ± 26.2 146.5 – 268.2 170.5 ± 1.1 180.7 ± 26.8

Download data for profiler.firefox.com or download performance comparison data.

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

No significant performance differences relative to db74969.

All results
transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1500
       time:   [57.234 ms 57.279 ms 57.329 ms]
       thrpt:  [1.7034 GiB/s 1.7049 GiB/s 1.7063 GiB/s]
Found 4 outliers among 100 measurements (4.00%)
3 (3.00%) high mild
1 (1.00%) high severe
transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1500
       time:   [57.211 ms 57.266 ms 57.322 ms]
       thrpt:  [1.7037 GiB/s 1.7053 GiB/s 1.7070 GiB/s]
transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1500
       time:   [3.5174 ms 3.5181 ms 3.5189 ms]
       thrpt:  [284.18   B/s 284.24   B/s 284.30   B/s]
Found 11 outliers among 100 measurements (11.00%)
7 (7.00%) high mild
4 (4.00%) high severe
transfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1500
       time:   [81.114 ms 81.242 ms 81.371 ms]
       thrpt:  [122.89 Kelem/s 123.09 Kelem/s 123.28 Kelem/s]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) low mild
streams-flow-controlled/walltime/1-streams/each-4194304-bytes
       time:   [12.614 ms 12.619 ms 12.624 ms]
       thrpt:  [316.85 MiB/s 316.99 MiB/s 317.12 MiB/s]
Found 6 outliers among 100 measurements (6.00%)
6 (6.00%) high mild
streams-flow-controlled/walltime/10-streams/each-1048576-bytes
       time:   [34.300 ms 34.333 ms 34.368 ms]
       thrpt:  [290.97 MiB/s 291.27 MiB/s 291.54 MiB/s]
Found 14 outliers among 100 measurements (14.00%)
9 (9.00%) high mild
5 (5.00%) high severe
streams/walltime/1-streams/each-1000-bytes
       time:   [155.65 µs 156.28 µs 157.09 µs]
       thrpt:  [6.0707 MiB/s 6.1022 MiB/s 6.1269 MiB/s]
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild
streams/walltime/1000-streams/each-1-bytes
       time:   [4.4836 ms 4.4894 ms 4.4950 ms]
       thrpt:  [217.25 KiB/s 217.53 KiB/s 217.81 KiB/s]
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) low mild
streams/walltime/1000-streams/each-1000-bytes
       time:   [14.731 ms 14.744 ms 14.757 ms]
       thrpt:  [64.624 MiB/s 64.681 MiB/s 64.737 MiB/s]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild
transfer/walltime/pacing-false/same-seed
       time:   [3.8820 ms 3.8852 ms 3.8890 ms]
       thrpt:  [1.0044 GiB/s 1.0054 GiB/s 1.0063 GiB/s]
transfer/walltime/pacing-false/varying-seeds
       time:   [3.8854 ms 3.8927 ms 3.9013 ms]
       thrpt:  [1.0013 GiB/s 1.0035 GiB/s 1.0054 GiB/s]
Found 23 outliers among 100 measurements (23.00%)
23 (23.00%) low mild
transfer/walltime/pacing-true/same-seed
       time:   [4.1921 ms 4.2008 ms 4.2085 ms]
       thrpt:  [950.46 MiB/s 952.20 MiB/s 954.18 MiB/s]
transfer/walltime/pacing-true/varying-seeds
       time:   [4.1185 ms 4.1216 ms 4.1251 ms]
       thrpt:  [969.66 MiB/s 970.50 MiB/s 971.22 MiB/s]

Instructions per cycle

Criterion reported no significant timing changes.

All benchmarks
Benchmark IPC before IPC after ΔIPC
transfer/walltime/pacing-false/same-seed 2.89 2.86 -1.1%
streams-flow-controlled/walltime/10-streams/each-1048576-bytes 3.12 3.15 +1.0%
transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1500 3.22 3.19 -0.9%
streams/walltime/1000-streams/each-1000-bytes 2.99 2.97 -0.7%
streams-flow-controlled/walltime/1-streams/each-4194304-bytes 2.99 3.00 +0.3%
transfer/walltime/pacing-true/same-seed 2.88 2.89 +0.3%
streams/walltime/1000-streams/each-1-bytes 3.28 3.27 -0.3%
transfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1500 3.20 3.19 -0.3%
transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1500 2.23 2.23 +0.2%
transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1500 3.19 3.20 +0.2%
streams/walltime/1-streams/each-1000-bytes 2.53 2.53 +0.2%
transfer/walltime/pacing-false/varying-seeds 2.87 2.87 +0.0%
transfer/walltime/pacing-true/varying-seeds 2.88 2.88 +0.0%
Profiles for profiler.firefox.com (64)

Download data for profiler.firefox.com or download performance comparison data.

control_stream_recv: &mut Box<dyn RecvStream>,
now: Instant,
) -> Res<Option<State>> {
let mut budget = MAX_DATAGRAM_BYTES_PER_READ;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This bounds the events queued per read_control_stream call, but not the events outstanding. The budget starts fresh on every call (from both Session::receive and header_unblocked), and consuming the stream data reopens flow control, so a peer can send another window of tiny capsules every RTT. If the application doesn't poll events between process calls, or polls more slowly than the peer sends, each read adds up to another ~4096 Datagram events and the queue still grows without bound.

Would it work to track outstanding queued bytes per session, released as events are polled, like transport's max_buffered_datagrams? That bounds memory regardless of how reads are batched.

Some(Capsule::Datagram { payload }) => match self.dgram_context_id(payload) {
Ok(slice) => {
events.new_datagram(self.session_id, slice, self.connect_type());
let cost = slice.len().saturating_add(PER_DATAGRAM_OVERHEAD);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will also drop legitimate traffic. With an multi-MB stream receive window, a single lost packet blocks the stream; when the retransmission fills the gap, everything buffered behind it becomes readable in one read, and anything past the first 256 KB is discarded even though the peer sent it within flow control and we've already ACKed it. A tunneled flow would see a burst loss after every recovery event. That's the same scenario the hold_first tests construct, just with benign traffic.

A cap on outstanding (unpolled) events, per the comment above, avoids this, since a well-behaved application drains between reads.

Also, this undercounts actual memory per event. Each queued event is an Http3ClientEvent/Http3ServerEvent in a VecDeque slot plus a Bytes header, and the backing allocation is the full capsule payload including the context-ID prefix (not just slice.len()). For an empty datagram I suspect that's well over 64 bytes, so the real bound per read is a multiple of the documented 256 KB. The 64 was chosen for transport's queue entries, not HTTP/3 events.

events.new_datagram(self.session_id, slice, self.connect_type());
} else {
// RFC 9221 Section 5.3 lets the receiver drop datagrams.
debug!("[{self}]: dropped datagram over the per-read budget");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two concerns: there's no counter, stat or event for these drops, so the application can't tell that it's losing datagrams (which makes the case in the previous comment hard to diagnose), and under the flood this is guarding against it logs once per dropped capsule, which can be hundreds of thousands of lines per read with debug logging on. Could we count the drops and log once per read (and ideally surface the count in stats)?

@@ -75,7 +82,14 @@ impl Protocol for Session {
match capsule {
Some(Capsule::Datagram { payload }) => match self.dgram_context_id(payload) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Datagrams over the budget are still fully decoded before being dropped: Capsule::decode does Bytes::from(payload.to_vec()) (frames/capsule.rs:59), and the context ID is parsed, then the allocation is freed. The loop also keeps reading after the budget is exhausted. So under a flood each read still does work proportional to the whole flow-control window, and the CPU side of the amplification is unchanged. Could we stop reading once the budget is exhausted, or check the length before allocating?

const MAX_DATAGRAM_BYTES_PER_READ: usize = 256 * 1024;

/// Per-event bookkeeping charge, as `PER_DATAGRAM_OVERHEAD` in neqo-transport's datagram queue.
const PER_DATAGRAM_OVERHEAD: usize = 64;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This duplicates the private constant in neqo-transport/src/datagram_queue.rs:62, and the doc comment says it mirrors it, but nothing ties them together; if transport changes its value this silently diverges. Maybe export the transport one (or a cost helper) instead? However, see below -- using PER_DATAGRAM_OVERHEAD from transport probably isn't what we want, so perhaps just use a different constant (and name)

}

/// Establishes a session that carries datagrams in capsules.
fn capsule_session() -> (Http3Client, Http3Server, ServerSession) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is largely the same as establish_capsule_session in neqo-http3/tests/connect_udp.rs:770. It also requires making tests::webtransport and its connect() public so connect-udp unit tests can reach into the WebTransport test module. Could the two setups share one helper, or the flood tests live alongside the existing integration tests in tests/connect_udp.rs?

Comment on lines +260 to +264
if hold_first {
held.push(flight.remove(0));
}
flight = sender.exchange(receiver.exchange(flight));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hold_first withholds the first datagram of every flight, not just the one carrying the first stream data, so later ACK-only or MAX_STREAM_DATA packets are held as well and delivered together with the gap-filler. The exact assertions (== budgeted, == budgeted - 1) depend on the capsules landing so that everything becomes readable in exactly one read. A change in packetization or pacing could break them for reasons unrelated to the budget logic. Holding only the first packet of the first flight would make the tests less sensitive to that.

@larseggert

Copy link
Copy Markdown
Collaborator Author

@jesup please make the changes you think this PR needs to land it.

@mxinden mxinden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this low severity attack warants the complexity this fix introduces.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client-side Issue relates more to clients extended-connect WebTransport, CONNECT, connect-udp, HTTP datagrams p2 Issues that we want to fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants