Skip to content

fix http/2 header payload padding parsing#65729

Open
DeagleGross wants to merge 2 commits intodotnet:mainfrom
DeagleGross:dmkorolev/h2-HEADERS-prio-pad-overflow
Open

fix http/2 header payload padding parsing#65729
DeagleGross wants to merge 2 commits intodotnet:mainfrom
DeagleGross:dmkorolev/h2-HEADERS-prio-pad-overflow

Conversation

@DeagleGross
Copy link
Member

The padding length check for HTTP/2 HEADERS frames did not account for the extra 5 bytes consumed by the PRIORITY flag (4-byte stream dependency + 1-byte weight).

Kestrel was throwing an exception later instead of validating the bytes properly and rejecting immediately:

Frame header (bytes 0-8):
----------------------------------------------------------------------------
00 00 06  → Length = 6
01        → Type = HEADERS (0x01)
2D        → Flags = 0x2D = 0b00101101
            = END_STREAM (0x01) | END_HEADERS (0x04) | PADDED (0x08) | PRIORITY (0x20)
00 00 00 01 → StreamId = 1

Payload (9-14):
----------------------------------------------------------------------------
01        → HeadersPadLength = 1     ← parsed because PADDED flag is set
00 00 00 00 → StreamDependency = 0  ← parsed because PRIORITY flag is set
10        → Weight = 16             ← parsed because PRIORITY flag is set
(nothing) → 0 bytes of HPACK data
(nothing) → 0 bytes of padding (but PadLength says 1!)

@DeagleGross DeagleGross self-assigned this Mar 10, 2026
@DeagleGross DeagleGross added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Mar 10, 2026
@DeagleGross DeagleGross requested a review from halter73 as a code owner March 10, 2026 19:05
Copilot AI review requested due to automatic review settings March 10, 2026 19:05
@DeagleGross DeagleGross changed the title fix http/2 header payload parsing fix http/2 header payload padding parsing Mar 10, 2026
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

Fixes HTTP/2 HEADERS frame padding validation in Kestrel so frames with both PADDED and PRIORITY flags correctly account for the extra 5 priority bytes when determining whether padding exceeds the available payload.

Changes:

  • Update HEADERS padding-length validation to subtract the correct “extended fields” length (padding + optional priority) before comparing against PadLength.
  • Expose HeadersPayloadOffset on Http2Frame to support the updated validation logic.
  • Add a functional test covering the specific invalid HEADERS payload scenario (PADDED + PRIORITY where padding exceeds remaining payload).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Shared/ServerInfrastructure/Http2/Http2Frame.Headers.cs Exposes the computed HEADERS extended-fields offset used for payload/padding calculations.
src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs Fixes HEADERS padding validation by subtracting the correct offset when PRIORITY is present.
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs Adds regression coverage for invalid PADDED+PRIORITY HEADERS frame padding.

@DeagleGross DeagleGross enabled auto-merge (squash) March 12, 2026 13:16
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 feature-kestrel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants