Skip to content

Configure ZstandardStream decompression with MaxWindowLog=23 per RFC 9659 - #130024

Merged
rzikm merged 4 commits into
mainfrom
copilot/update-zstandardstream-maxwindowlog
Jul 1, 2026
Merged

rzikm merged 4 commits into
mainfrom
copilot/update-zstandardstream-maxwindowlog

Conversation

Copilot AI commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

RFC 9659 requires HTTP implementations to cap Zstandard decompression window size at 8 MB (log₂=23) to prevent memory exhaustion from maliciously crafted responses. Previously, DecompressionHandler constructed ZstandardStream with no window limit.

Changes

  • DecompressionHandler.cs: Pass ZstandardDecompressionOptions { MaxWindowLog = 23 } when constructing the decompression ZstandardStream:

    // Before
    new ZstandardStream(originalStream, CompressionMode.Decompress);
    
    // After
    new ZstandardStream(originalStream, new ZstandardDecompressionOptions { MaxWindowLog = 23 });

    Any frame whose Window_Descriptor declares >8 MB is now rejected by the decoder with an IOException, wrapped into HttpRequestException by the HTTP stack.

  • HttpClientHandlerTest.Decompression.cs: Added GetAsync_ZstandardDecompression_ResponseWindowSizeExceedsMaxWindowLog_Fails — compresses a payload with WindowLog=24 (16 MB), sends it with Content-Encoding: zstd, and asserts the client throws HttpRequestException whose inner IOException message contains "maxWindowLog", confirming the RFC 9659 limit is enforced rather than a generic error.

This changes makes #129986 largely unnecessary

Copilot AI self-assigned this Jun 30, 2026
Copilot AI review requested due to automatic review settings June 30, 2026 08:49
Copilot AI removed the request for review from Copilot June 30, 2026 08:49
Modify DecompressionHandler.cs to use ZstandardDecompressionOptions
with MaxWindowLog=23 (8MB) when constructing the ZstandardStream for
automatic decompression, aligning with RFC 9659 guidance.

Add a functional test verifying that Zstandard-encoded responses with
window log > 23 are rejected with HttpRequestException.

Co-authored-by: rzikm <[email protected]>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 09:19
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 09:21
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI changed the title [WIP] Update ZstandardStream to set MaxWindowLog to 23 for decompression Configure ZstandardStream decompression with MaxWindowLog=23 per RFC 9659 Jun 30, 2026
Copilot finished work on behalf of rzikm June 30, 2026 09:23
Copilot AI requested a review from rzikm June 30, 2026 09:23
@rzikm
rzikm marked this pull request as ready for review June 30, 2026 09:43
Copilot AI review requested due to automatic review settings June 30, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 tightens SocketsHttpHandler’s automatic Zstandard (zstd) response decompression by configuring the decoder with a maximum allowed window size (log₂=23), reducing the risk of excessive memory usage when processing responses that advertise large windows.

Changes:

  • Configure DecompressionHandler to construct ZstandardStream with ZstandardDecompressionOptions { MaxWindowLog = 23 }.
  • Add a functional test that serves a Content-Encoding: zstd response compressed with a larger window and asserts the client fails with HttpRequestException.

Reviewed changes

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

File Description
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs Applies a bounded Zstandard decompression configuration for HTTP response decoding.
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Decompression.cs Adds a regression test validating failure when the response’s declared Zstandard window exceeds the configured cap.

Copilot AI changed the title Configure ZstandardStream decompression with MaxWindowLog=23 per RFC 9659 Address review comments: cache ZstandardDecompressionOptions, simplify test assertion Jun 30, 2026
Copilot finished work on behalf of rzikm June 30, 2026 10:26
@rzikm rzikm changed the title Address review comments: cache ZstandardDecompressionOptions, simplify test assertion Configure ZstandardStream decompression with MaxWindowLog=23 per RFC 9659 Jun 30, 2026
@rzikm
rzikm requested a review from a team June 30, 2026 10:32
@MihaZupan MihaZupan added this to the 11.0.0 milestone Jun 30, 2026
@JakeYallop

Copy link
Copy Markdown
Contributor

Is this not technically a breaking change?

@rzikm

rzikm commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Is this not technically a breaking change?

Zstandard automatic decompression is new in .NET 11, we don't care about this kind of breaking changes between preview versions.

@rzikm

rzikm commented Jul 1, 2026

Copy link
Copy Markdown
Member

/ba-g test failures are unrelated

@rzikm
rzikm enabled auto-merge (squash) July 1, 2026 09:01
@rzikm
rzikm merged commit 498b521 into main Jul 1, 2026
89 of 91 checks passed
@rzikm
rzikm deleted the copilot/update-zstandardstream-maxwindowlog branch July 1, 2026 09:01
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview7 Jul 2, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…9659 (#130024)

RFC 9659 requires HTTP implementations to cap Zstandard decompression
window size at 8 MB (log₂=23) to prevent memory exhaustion from
maliciously crafted responses. Previously, `DecompressionHandler`
constructed `ZstandardStream` with no window limit.

## Changes

- **`DecompressionHandler.cs`**: Pass `ZstandardDecompressionOptions {
MaxWindowLog = 23 }` when constructing the decompression
`ZstandardStream`:
  ```csharp
  // Before
  new ZstandardStream(originalStream, CompressionMode.Decompress);

  // After
new ZstandardStream(originalStream, new ZstandardDecompressionOptions {
MaxWindowLog = 23 });
  ```
Any frame whose Window_Descriptor declares >8 MB is now rejected by the
decoder with an `IOException`, wrapped into `HttpRequestException` by
the HTTP stack.

- **`HttpClientHandlerTest.Decompression.cs`**: Added
`GetAsync_ZstandardDecompression_ResponseWindowSizeExceedsMaxWindowLog_Fails`
— compresses a payload with `WindowLog=24` (16 MB), sends it with
`Content-Encoding: zstd`, and asserts the client throws
`HttpRequestException` whose inner `IOException` message contains
`"maxWindowLog"`, confirming the RFC 9659 limit is enforced rather than
a generic error.

This changes makes #129986
largely unnecessary

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: rzikm <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants