Open
Conversation
Return early when a Retry token exceeds the implementation's fixed plaintext capacity so decryption never slices past the local stack buffer. Add a regression test that exercises an oversized token length and expects clean rejection. Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens QUIC Retry token validation by rejecting tokens larger than the implementation’s fixed capacity before any slicing/decryption occurs, preventing a potential out-of-bounds slice during AES-GCM decrypt.
Changes:
- Add an upper-bound length check in
validateRetryToken()to reject tokens larger thanTOKEN_MAX_LEN. - Add an explicit ciphertext-length bound check (
ct_len <= TOKEN_MAX_PLAINTEXT_LEN) before slicing/decrypt. - Add a regression test ensuring oversized Retry tokens are cleanly rejected (no panic).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validateRetryToken()aligned withTOKEN_MAX_PLAINTEXT_LEN/TOKEN_MAX_LENVulnerability
This Retry token format is implemented as:
That means the largest valid Retry token for this implementation is 92 bytes. Before this change,
validateRetryToken()only checked the minimum token size, then derivedct_lenfrom the attacker-controlled token length and immediately slicedplaintext[0..ct_len]for AES-GCM decryption.A remote peer could therefore send an Initial packet carrying an oversized Retry token, for example:
ct_len = 65and already exceeds the 64-byte plaintext bufferIn safe builds that panics during validation; in unchecked builds it risks writing past the fixed stack buffer in this network-facing token parser.
Validation
zig build testzig buildzig build fuzzReferences