Repository navigation
Configure ZstandardStream decompression with MaxWindowLog=23 per RFC 9659 - #130024
Conversation
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]>
Co-authored-by: rzikm <[email protected]>
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
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
DecompressionHandlerto constructZstandardStreamwithZstandardDecompressionOptions { MaxWindowLog = 23 }. - Add a functional test that serves a
Content-Encoding: zstdresponse compressed with a larger window and asserts the client fails withHttpRequestException.
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. |
…y test assertion Co-authored-by: rzikm <[email protected]>
|
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. |
|
/ba-g test failures are unrelated |
…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]>
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,
DecompressionHandlerconstructedZstandardStreamwith no window limit.Changes
DecompressionHandler.cs: PassZstandardDecompressionOptions { MaxWindowLog = 23 }when constructing the decompressionZstandardStream:Any frame whose Window_Descriptor declares >8 MB is now rejected by the decoder with an
IOException, wrapped intoHttpRequestExceptionby the HTTP stack.HttpClientHandlerTest.Decompression.cs: AddedGetAsync_ZstandardDecompression_ResponseWindowSizeExceedsMaxWindowLog_Fails— compresses a payload withWindowLog=24(16 MB), sends it withContent-Encoding: zstd, and asserts the client throwsHttpRequestExceptionwhose innerIOExceptionmessage contains"maxWindowLog", confirming the RFC 9659 limit is enforced rather than a generic error.This changes makes #129986 largely unnecessary