Skip to content

transport: Client skips DCID check in WaitInitial; off-path junk fills saved datagrams #4372

Open

Description

@larseggert

Related: #2866, #1185, #1024
Code has moved since f53c12bc; still present at e09257ab neqo-transport/src/connection/mod.rs:1668.
See also: #4367

A neqo client that has sent its first Initial and has not yet heard from the server can be made to throw away the server's early 1-RTT packets by four spoofed 41-byte datagrams from an off-path sender. That sender needs no connection ID, key, or view of any packet. It only needs to send to the client's UDP port, from the server's spoofed address and port, during the roughly one round trip before the server's first packet arrives. The result is a bounded delay, not a failure: the connection still completes, and the discarded data arrives later by retransmission. In the attached reproducer, at a 100 ms round trip, the server's early stream data becomes readable at 300 ms instead of 100 ms.

The cause is in Connection::preprocess_packet() (neqo-transport/src/connection/mod.rs:1667). There, State::WaitInitial returns Continue without the cid_manager.is_valid(packet.dcid()) check that every later state applies, contrary to RFC 9000, Section 5.2.1. A Handshake or short-header packet with an unknown DCID then fails to decrypt with Error::KeysPending and is placed in SavedDatagrams. That queue keeps the first four datagrams per epoch and refuses the rest. The ApplicationData store is only drained in set_connected(), so junk saved during WaitInitial holds every slot, and the server's genuine 1-RTT packets sent right behind its Finished are refused. A full queue also disables the early ClientHello resend path. The Handshake-epoch store can be filled the same way; that only matters if the server's Handshake packets overtake its ServerHello, and the reproducer measured 400 ms to Connected instead of 100 ms in that case.

The effect requires a server that sends data before the handshake completes, which most HTTP/3 servers do with SETTINGS and QPACK streams. Between two neqo HTTP/3 endpoints there is no visible effect unless the server's first datagrams are also reordered. A reply to a request the client sends on connecting is not delayed.

The behaviour dates from 6b6d82585ad8 (v0.4.11). Four datagrams have been enough since the capacity was lowered to 4 in v0.4.29. The attached reproducer is a deterministic integration test that uses only the public API and runs three handshakes; the two control handshakes show the same junk dropped as Invalid DCID once the client has left WaitInitial. A one-line patch that moves a client's WaitInitial into the DCID-checking arm is attached, along with a regression test.

Details

A client that has sent its first Initial and is still in State::WaitInitial does not compare the destination connection
ID of an incoming packet with the connection IDs it issued. Every later state up to Confirmed does.
Connection::preprocess_packet(), neqo-transport/src/connection/mod.rs:1667-1681:

State::WaitInitial => PreprocessResult::Continue,
State::WaitVersion | State::Handshaking | State::Connected | State::Confirmed => {
    if self.cid_manager.is_valid(packet.dcid()) {
        …
        PreprocessResult::Continue
    } else {
        self.stats.borrow_mut().pkt_dropped(format!("Invalid DCID {:?}", packet.dcid()));
        PreprocessResult::Next
    }
}

For an Initial packet the missing check has no effect, because the packet still has to decrypt. A Handshake or short
header packet cannot be decrypted in this state, and it is not dropped either: it is put into the saved-datagram queue,
which has four slots per epoch. Four datagrams from a sender that knows no connection ID fill it. RFC 9000,
Section 5.2.1 has a client discard packets whose destination connection ID is not one it selected.

The existing unit test extra_initial_invalid_cid (neqo-transport/src/connection/tests/handshake.rs:909) already hands
a client in WaitInitial a Handshake packet with a wrong connection ID. With
assert_eq!(client.stats().saved_datagrams, 0); added as its last line, it fails at this commit: the counter is 1.

The path of a packet with an unknown connection ID

  1. input() requires the datagram's addresses to be those of the primary path (connection/mod.rs:1782-1792). A sender
    that spoofs the server's address and port passes.
  2. Public::decode() accepts any first byte with the top bit clear as a short header packet, takes the next bytes as
    the connection ID (as many as the client's connection IDs are long), and asks for 20 more bytes
    (packet/mod.rs:684-688).
  3. preprocess_packet() returns Continue for WaitInitial, as quoted above.
  4. Public::decrypt() finds no keys for the epoch. CryptoStates::rx_pending() says that they are still to come
    (crypto.rs:1083-1089), so the result is Error::KeysPending(epoch) (packet/mod.rs:959-962).
  5. input_path() answers that error with save_datagram() (connection/mod.rs:1892-1898).
  6. SavedDatagrams::save() keeps the first four datagrams per epoch and discards all that follow
    (neqo-transport/src/saved.rs:46-55, CAPACITY = 4):
if store.len() < Self::CAPACITY {
    debug!("saving {epoch:?} datagram of {} bytes", d.len());
    store.push(SavedDatagram { d, t });
} else {
    info!("not saving {epoch:?} datagram of {} bytes", d.len());
}

The store for short header packets is emptied only when the handshake completes: set_connected() calls
make_available(Epoch::ApplicationData) (connection/mod.rs:3829). Four junk datagrams that arrive before the first
packet from the server therefore hold all four slots for the rest of the handshake.

What the slots are for

In an ordinary handshake the server sends 1-RTT packets right behind its Finished (most real HTTP/3 servers send their
SETTINGS and the QPACK streams there; neqo's own HTTP/3 server does not, it sends nothing before the handshake
completes). The client has no 1-RTT keys until the application has called authenticated(), so it saves those
packets and processes them as soon as it is Connected. With the queue full, save() discards them instead. They are
never acknowledged, and the server sends the data again once it has declared the packets lost. When the client becomes
Connected, it takes the four junk datagrams out of the queue, and only then drops each one with Invalid DCID.

Measured with a 100 ms round trip and five bytes of stream data behind the server's Finished; the junk datagrams are
41 bytes, 0x40 followed by 40 bytes of 0xee:

junk datagrams arrive when the client is in saved dropped on arrival stream readable when Connected readable after
0 yes 100 ms
4 WaitVersion / Handshaking 0 4 (Invalid DCID) yes 100 ms
3 WaitInitial 3 0 yes 100 ms
4 WaitInitial 4 0 no 300 ms, after one packet declared lost by the server

In the last row the client logs saving ApplicationData datagram of 41 bytes four times, and then
not saving ApplicationData datagram of … bytes for the server's 1-RTT packet. The "saved" column is
Stats::saved_datagrams, which counts attempts to save, including those a full queue refuses (400 junk datagrams give
400); it equals the number actually held only up to four, which is all the table and the reproducer's junk_saved
use.

The code already treats a wrong connection ID in this state as a reason to ignore a packet, but only for the early resend
of the ClientHello: the arm at connection/mod.rs:1638-1648 requires self.cid_manager.is_valid(packet.dcid()), and that
is what extra_initial_invalid_cid tests. The packet refused there falls through to line 1667 and into the queue. The
same arm also requires !self.saved_datagrams.is_either_full(), so a queue filled with junk switches that early resend
(RFC 9002, Section 6.2.3) off for genuine packets as well.

The behaviour was introduced in 6b6d82585ad8 ("1rtt reordering test (#894)", 2020-08-25), first in release v0.4.11:
before it, a client in WaitInitial dropped what it could not decrypt; from it on, 32 junk datagrams filled the queue,
and a061f1ab4b6a ("Updated MAX_SAVED_DATAGRAMS from 32 to 4. (#1185)", v0.4.29) lowered that to four.

Impact

A sender that is not on the path, and can spoof the server's address towards the client's UDP port while the client waits
for the server's first packet, makes the client throw away the 1-RTT packets that the server sends before the handshake
completes. The sender needs the two addresses and ports and nothing else: no connection ID, no key, no sight of any
packet. The connection still completes; the discarded data arrives by retransmission, in the measurement above at 300 ms
instead of 100 ms. That figure is for a client that sends nothing after connecting; when the client sends a request as
soon as it is connected, the reply arrives on time (200 ms with and without junk), and only the server's early data is
late. The effect also needs a server that sends data right behind its Finished: between two neqo HTTP/3 endpoints the
full queue has no visible effect, because neqo's server sends nothing before the handshake completes, unless the
server's first datagrams are also reordered (below).

Four datagrams with a Handshake long header do the same to the other store. That one matters only when the server's
Handshake packets overtake its ServerHello: with the server's two datagrams delivered in reverse order and four such junk
datagrams saved, the client in the same setup is Connected after 400 ms instead of 100 ms.

This is a small, bounded denial of service: a delay, not a failure. The window is the time the client spends in
WaitInitial, and the attacker has to know or guess the client's port. A sender that sees no traffic has to guess the
moment as well, which in practice means sending to every candidate port all the time, already a flood in its own right.
Memory is bounded too: the client holds at most
eight of the attacker's datagrams (four per epoch) until the keys arrive. A client with zero-length connection IDs has
nothing to compare and is not helped by the check; for it, junk that arrives after the server's first packet, in
Handshaking, is saved as well. Neither is a client whose Initial the attacker can read, because that
attacker has a valid connection ID; that attacker gains nothing here, though, since it can already forge the server's
first packet.

Suggested fix

The attached patch applies the connection ID check in Connection::preprocess_packet()
(neqo-transport/src/connection/mod.rs) to a client in WaitInitial too, by moving that state into the existing
DCID-checking arm. Only a server keeps the exception: in that state it is looking at the first Initial, which carries a
connection ID that the client chose and which is added to the connection ID manager only later, in start_handshake().
A client's own initial connection ID is registered in ConnectionIdManager::new(), and Version Negotiation and Retry
are handled earlier in the same function, so no legitimate packet to a client is affected. The one check covers both
the Handshake and the ApplicationData store; the early-resend arm for packets with a valid connection ID is unchanged.

--- a/neqo-transport/src/connection/mod.rs
+++ b/neqo-transport/src/connection/mod.rs
@@ -1664,8 +1664,14 @@ impl Connection {
                     .pkt_dropped("Received while in Init state");
                 PreprocessResult::Next
             }
-            State::WaitInitial => PreprocessResult::Continue,
-            State::WaitVersion | State::Handshaking | State::Connected | State::Confirmed => {
+            // A server in this state is looking at the first Initial packet, which
+            // carries a connection ID that the client chose.
+            State::WaitInitial if self.role == Role::Server => PreprocessResult::Continue,
+            State::WaitInitial
+            | State::WaitVersion
+            | State::Handshaking
+            | State::Connected
+            | State::Confirmed => {
                 if self.cid_manager.is_valid(packet.dcid()) {

With the patch, such junk datagrams are counted in dropped_rx (Invalid DCID) on arrival instead of in
saved_datagrams, and the reproducer prints OK. As noted under Impact, a client with zero-length connection IDs is
not helped by the check. Limiting that case needs a change of policy in SavedDatagrams::save(), for example
replacing the oldest entry when a store is full instead of refusing the newest; this was not tested and is not part of
the patch. The patch also adds a regression test, two lines at the end of extra_initial_invalid_cid
(neqo-transport/src/connection/tests/handshake.rs) that fail before the change and pass after it:

assert_eq!(client.stats().saved_datagrams, 0);
assert_eq!(client.stats().dropped_rx, 1);

Proposed patches

patches/1.patch
# neqo-transport/src/connection/mod.rs
# Check the destination connection ID of packets a client receives in WaitInitial, so undecryptable packets
#   with an unknown ID are dropped, not saved
#
# Connection::preprocess_packet() is where every state from WaitVersion to Confirmed drops a packet whose DCID
#   the connection never issued, but WaitInitial returned Continue unconditionally; a client in that state
#   therefore passed Handshake and short-header packets with any DCID to decrypt(), got KeysPending, and
#   stored them in SavedDatagrams (4 slots per epoch), crowding out the server's genuine early 1-RTT/Handshake
#   packets. The patch moves WaitInitial into the existing DCID-checking arm and keeps the unconditional pass
#   only for a server, which in that state is looking at the client's first Initial whose DCID the client
#   chose and which is only added to the CID manager later, in start_handshake(). A client's own initial CID
#   is registered in ConnectionIdManager::new() (also when zero-length), and Version Negotiation and Retry are
#   handled and returned earlier in the same function, so no legitimate client-side packet is affected; both
#   junk stores (Handshake and ApplicationData) are covered by the one check, and the existing early-resend
#   arm for valid-DCID packets is unchanged. The regression test is two asserts added to the existing
#   extra_initial_invalid_cid test (saved_datagrams == 0, dropped_rx == 1), which fail before the change and
#   pass after. Checked: cargo test --locked --workspace --exclude mtu passes, cargo +nightly fmt --check and
#   cargo clippy --locked --all-targets -- -D warnings are clean. Behaviour change to note: such packets are
#   now counted in dropped_rx ('Invalid DCID') on arrival instead of in saved_datagrams.
# reviewer: good — Fixes the cause in the right place (client in WaitInitial now gets the same connection ID
#   check as later states, server keeps the exception it needs), covers both queues, comes with a test that
#   fails before and passes after, and the full test suite, clippy and format check pass with it.
# our check: FIXED · confidence high
#
diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs
index c7261652..7d62ec79 100644
--- a/neqo-transport/src/connection/mod.rs
+++ b/neqo-transport/src/connection/mod.rs
@@ -1664,8 +1664,14 @@ impl Connection {
                     .pkt_dropped("Received while in Init state");
                 PreprocessResult::Next
             }
-            State::WaitInitial => PreprocessResult::Continue,
-            State::WaitVersion | State::Handshaking | State::Connected | State::Confirmed => {
+            // A server in this state is looking at the first Initial packet, which
+            // carries a connection ID that the client chose.
+            State::WaitInitial if self.role == Role::Server => PreprocessResult::Continue,
+            State::WaitInitial
+            | State::WaitVersion
+            | State::Handshaking
+            | State::Connected
+            | State::Confirmed => {
                 if self.cid_manager.is_valid(packet.dcid()) {
                     if self.role == Role::Server && packet.packet_type() == packet::Type::Handshake
                     {
diff --git a/neqo-transport/src/connection/tests/handshake.rs b/neqo-transport/src/connection/tests/handshake.rs
index 00d106d7..a531886e 100644
--- a/neqo-transport/src/connection/tests/handshake.rs
+++ b/neqo-transport/src/connection/tests/handshake.rs
@@ -929,6 +929,10 @@ fn extra_initial_invalid_cid() {
     let dgram_copy = Datagram::new(s_hs.destination(), s_hs.source(), s_hs.tos(), copy);
     let nothing = client.process(Some(dgram_copy), now).dgram();
     assert!(nothing.is_none());
+    // Nor does it keep the packet until it has keys for it: the space for
+    // saved datagrams is small and is needed for packets from the server.
+    assert_eq!(client.stats().saved_datagrams, 0);
+    assert_eq!(client.stats().dropped_rx, 1);
 }
 
 #[test]

When fixing this, please carry this line into the commit message:

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-XDPAIHPP.

Activity

  1. added
    client-side
    on Nov 12, 2026
  2. self-assigned this
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

client-sidep3

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions