Skip to content

fix(retry): ensure Retry Source CID differs from client DCID#5953

Open
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
MarkedMuichiro:fix/retry-src-cid-collision-check
Open

fix(retry): ensure Retry Source CID differs from client DCID#5953
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
MarkedMuichiro:fix/retry-src-cid-collision-check

Conversation

@MarkedMuichiro
Copy link
Copy Markdown
Contributor

Fixes #5302

Problem

When generating a Retry packet, CxPlatRandom produces a random Source Connection ID but does not check that it differs from the client's Destination CID. RFC 9000 §17.2.5.1 requires that the Source Connection ID in a Retry packet MUST NOT equal the Destination Connection ID sent by the client.

While a collision is astronomically unlikely, the check is required for RFC compliance.

Fix

Wrapped the CxPlatRandom call in a do-while loop that regenerates if the new CID matches the client's DCID:

do {
    CxPlatRandom(MsQuicLib.CidTotalLength, NewDestCid);
} while (RecvPacket->DestCidLen == MsQuicLib.CidTotalLength &&
         memcmp(NewDestCid, RecvPacket->DestCid, MsQuicLib.CidTotalLength) == 0);

The length guard is load-bearing — the client DCID length is client-controlled and can legitimately differ from CidTotalLength, so skipping it would risk comparing against a shorter buffer.

This also fixes a minor issue in the original: CxPlatRandom was called with sizeof(NewDestCid) which randomizes the full QUIC_CID_MAX_LENGTH buffer, but only MsQuicLib.CidTotalLength bytes are ever used downstream. The fix randomizes only the bytes that matter.

RFC 9000 \u00a717.2.5.1 requires the Source Connection ID in a Retry
packet to differ from the client's Destination CID. The random
generation was missing this check, allowing rare but non-compliant
collisions.

Fixes microsoft#5302
@MarkedMuichiro MarkedMuichiro requested a review from a team as a code owner April 17, 2026 16:31
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.

QUIC: Retry Source CID May Match Client DCID

1 participant