fix(quic): bound decrypt header associated data#11
fix(quic): bound decrypt header associated data#11alanhoff wants to merge 4 commits intoendel:mainfrom
Conversation
Reject oversized QUIC headers before copying them into the fixed-size associated-data buffer used during packet decryption, and add regression tests covering the oversize and unprotected-first-byte cases. Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens QUIC packet decryption by bounding construction of AEAD associated data (AD) to prevent stack-buffer overflow when reconstructing long headers (notably QUIC Initial packets with large tokens), and adds regression tests for the new behavior.
Changes:
- Introduce
buildHeaderBytes()to safely rebuild the unprotected header bytes into a fixed-size AD scratch buffer with length checks. - Reuse the bounded helper from both
decrypt()anddecryptWithKeyUpdate(). - Add tests covering oversized-header rejection and ensuring the first byte in AD is the unprotected value.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to harden QUIC packet decryption against malformed/attacker-controlled length fields and oversized headers used to build AEAD associated data (AD) during decryption.
Changes:
- Adds guards in
decrypt()anddecryptWithKeyUpdate()to preventremainder_lenunderflow and out-of-bounds payload slicing. - Minor cleanup of
encrypted_payloadslicing syntax.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add shared header rebuilding bounds checks and regression tests for malformed payload lengths in both decrypt paths. Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a QUIC decryption-time stack-buffer overflow risk by bounding reconstruction of AEAD associated data (the unprotected header) before copying it into a fixed-size scratch buffer, and adds regression tests to prevent reintroduction.
Changes:
- Added a shared
buildHeaderBytes()helper to reconstruct header bytes into a bounded 512-byte buffer (rejecting oversized headers early). - Reused the helper in both
decrypt()anddecryptWithKeyUpdate(), and added explicit malformed-length guards before slicing the encrypted payload. - Added unit tests covering oversized-header rejection, preservation of the unprotected first byte, and malformed payload length rejection in both decrypt paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use an explicit InvalidPacket-only error set for buildHeaderBytes so decrypt APIs do not inherit a broader helper error surface. Co-authored-by: Codex <noreply@openai.com>
Summary
Vulnerability
decrypt()anddecryptWithKeyUpdate()rebuild AEAD associated data by copying the unprotected packet header into a fixed 512-byte stack buffer. For long-header packets, that reconstructed header length includes the Initial token field. Because QUIC Initial packets carry a variable-length token, a malicious peer can send an internally well-formed packet whose header grows past 512 bytes and drive the memcpy past the end of the stack buffer.Concrete examples:
Validation
zig build testzig buildzig build fuzzgh issue list --repo endel/quic-zig --search "header buffer overflow decrypt token length initial packet" --limit 20References