Skip to content

Sync shared HPack/QPack changes from aspnetcore#125526

Open
Copilot wants to merge 2 commits intomainfrom
copilot/apply-auth-issues-fix
Open

Sync shared HPack/QPack changes from aspnetcore#125526
Copilot wants to merge 2 commits intomainfrom
copilot/apply-auth-issues-fix

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Closes dotnet/aspnetcore#18943

Huffman-encoded strings can expand significantly on decode (e.g. 10 encoded bytes → 16 decoded bytes). Both HPackDecoder and QPackDecoder validated the encoded string length against _maxHeadersLength before decoding, but never checked the decoded length — allowing Huffman-inflated headers to silently exceed the configured limit.

Description

  • HPackDecoder: After Huffman.Decode, check decodedLength > _maxHeadersLength and throw HPackDecodingException. Add Debug.Assert on the non-Huffman path confirming the pre-decode check is sufficient there.
  • QPackDecoder: Same fix — post-decode length check throwing QPackDecodingException.
  • Tests (HPackDecoderTest, QPackDecoderTest): Two new [Fact] tests each — HuffmanDecodedHeaderName_ExceedsLimitAfterDecoding_Throws and HuffmanDecodedHeaderValue_ExceedsLimitAfterDecoding_Throws — using a maxHeadersLength: 10 decoder with a 10-byte Huffman payload that decodes to 16 bytes ('0' has a 5-bit code: 00000).

Copilot AI and others added 2 commits March 13, 2026 16:17
…ow run 23059322485

Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
@MihaZupan MihaZupan changed the title Fix HPack/QPack Huffman decoded header length not checked against max limit Sync shared HPack/QPack changes from aspnetcore Mar 13, 2026
@MihaZupan
Copy link
Member

Backport of dotnet/aspnetcore#65771 to runtime

@MihaZupan MihaZupan marked this pull request as ready for review March 13, 2026 19:54
Copilot AI review requested due to automatic review settings March 13, 2026 19:54
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 closes a header-size enforcement gap in the shared HPack/QPack decoders by ensuring Huffman-decoded header names/values can’t exceed the configured maximum header length due to post-decode expansion.

Changes:

  • Add post-Huffman-decode length validation in HPackDecoder and QPackDecoder, throwing the appropriate decoding exception when the decoded length exceeds _maxHeadersLength.
  • Add debug assertions on the non-Huffman decode path documenting that the existing pre-decode length check is sufficient.
  • Add new unit tests for HPack and QPack to cover Huffman inflation scenarios where encoded length is within the limit but decoded length exceeds it.

Reviewed changes

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

File Description
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs Enforces _maxHeadersLength after Huffman decode to prevent inflated decoded strings from bypassing the limit.
src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs Mirrors the HPack fix for QPack by validating decoded length after Huffman decode.
src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs Adds regression tests that ensure oversized Huffman-decoded names/values throw and do not emit headers.
src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs Adds regression tests for the same Huffman expansion overflow scenario in QPack.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The runtime<->aspnetcore shared src is out of sync

3 participants