Skip to content

fix: Q/HPackDecoder limit validation after decoding#65771

Merged
DeagleGross merged 2 commits intodotnet:mainfrom
DeagleGross:dmkorolev/sec/hpackqpack-limits
Mar 13, 2026
Merged

fix: Q/HPackDecoder limit validation after decoding#65771
DeagleGross merged 2 commits intodotnet:mainfrom
DeagleGross:dmkorolev/sec/hpackqpack-limits

Conversation

@DeagleGross
Copy link
Member

There is a discrepancy between Http2Limits.MaxRequestHeaderFieldSize documentation and actual Q/HPackDecoders behavior:

/// <summary>
/// Indicates the size of the maximum allowed size of a request header field sequence, in octets. This limit applies to both name and value sequences in their compressed and uncompressed representations.
/// <para>
/// Value must be greater than 0, defaults to 2^15 octets (32 KiB).
/// </para>
/// </summary>
public int MaxRequestHeaderFieldSize

MaxRequestHeaderFieldSize clearly states that limits apply to both compressed and uncompressed data, but decoders dont check uncompressed length.

Current PR adds a validation check on uncompressed state and throws a corresponding exception per type.

@DeagleGross DeagleGross self-assigned this Mar 13, 2026
@DeagleGross DeagleGross added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Mar 13, 2026
Copilot AI review requested due to automatic review settings March 13, 2026 12:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns HPACK (HTTP/2) and QPACK (HTTP/3) decoder behavior with Http2Limits.MaxRequestHeaderFieldSize / Http3Limits.MaxRequestHeaderFieldSize documentation by enforcing the header field size limit on decoded (uncompressed) header name/value lengths in addition to the existing encoded (compressed) length checks.

Changes:

  • Add post-Huffman-decode validation to ensure decoded header name/value length does not exceed maxHeadersLength.
  • Throw HPackDecodingException / QPackDecodingException with the existing net_http_headers_exceeded_length message when the decoded length exceeds the limit.
  • Add targeted regression tests for both HPACK and QPACK covering Huffman expansion exceeding the limit.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Shared/runtime/Http2/Hpack/HPackDecoder.cs Enforces maxHeadersLength after Huffman decoding for header names/values.
src/Shared/runtime/Http3/QPack/QPackDecoder.cs Enforces maxHeadersLength after Huffman decoding for header names/values.
src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs Adds tests proving encoded-length pass + decoded-length fail now throws.
src/Shared/test/Shared.Tests/runtime/Http3/QPackDecoderTest.cs Adds equivalent tests for QPACK Huffman expansion scenarios.

You can also share your feedback on Copilot code review. Take the survey.

@DeagleGross DeagleGross merged commit c892018 into dotnet:main Mar 13, 2026
25 checks passed
@DeagleGross DeagleGross deleted the dmkorolev/sec/hpackqpack-limits branch March 13, 2026 14:09
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview3 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants