From 52813fce4794f39e427770f1c2d6f7b62d24ab4d Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:23:13 +0100 Subject: [PATCH] Handled DecompressionMethods.All --- .../OpenIddictPolyfills.cs | 15 +++++++++++++ .../OpenIddictClientSystemNetHttpHandlers.cs | 3 +++ .../OpenIddictClientSystemNetHttpOptions.cs | 1 + ...enIddictValidationSystemNetHttpHandlers.cs | 3 +++ ...penIddictValidationSystemNetHttpOptions.cs | 1 + ...nIddictClientSystemNetHttpHandlersTests.cs | 22 +++++++++++++++++++ ...ictValidationSystemNetHttpHandlersTests.cs | 22 +++++++++++++++++++ 7 files changed, 67 insertions(+) diff --git a/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs b/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs index 63110faf..1245f7ad 100644 --- a/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs +++ b/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs @@ -4,6 +4,7 @@ * the license and the contributors participating to this project. */ +using System.Net; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -71,6 +72,20 @@ internal static class OpenIddictPolyfills #endif } + extension(DecompressionMethods) + { +#if !NET + /// + /// Use all compression-decompression algorithms. + /// + /// + /// Note: the backing value (-1) is identical to the one used by the + /// DecompressionMethods.All member exposed by .NET Core 2.1 and higher. + /// + public static DecompressionMethods All => (DecompressionMethods) (-1); +#endif + } + extension(HMACSHA256) { #if !NET diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs index 90b0eac8..780754d9 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs @@ -614,6 +614,9 @@ public static partial class OpenIddictClientSystemNetHttpHandlers // Note: the algorithms that were not explicitly allowed are rejected even if they are natively // supported by the runtime (e.g to prevent using a decoder affected by a known vulnerability). + // + // DecompressionMethods.All (whose backing value is -1) has all the bits set and can be + // used to bypass the individual checks and allow all the algorithms supported by OpenIddict. var methods = _options.CurrentValue.AllowedDecompressionMethods; // Iterate the returned encodings and wrap the response stream using the specified algorithm. diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs index 7b421ef5..fea933fe 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs @@ -87,6 +87,7 @@ public sealed class OpenIddictClientSystemNetHttpOptions /// Note: while HTTP compression is never opted-in by default, encoded responses returned by servers /// that enforce content compression are still decoded. This property can be used to exclude specific /// algorithms (e.g to mitigate a vulnerability affecting one of the decoders used by the runtime). + /// DecompressionMethods.All can be used to allow all the algorithms supported by OpenIddict. /// public DecompressionMethods AllowedDecompressionMethods { get; set; } #if NET diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs index 3b02c45b..712407ff 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs @@ -610,6 +610,9 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers // Note: the algorithms that were not explicitly allowed are rejected even if they are natively // supported by the runtime (e.g to prevent using a decoder affected by a known vulnerability). + // + // DecompressionMethods.All (whose backing value is -1) has all the bits set and can be + // used to bypass the individual checks and allow all the algorithms supported by OpenIddict. var methods = _options.CurrentValue.AllowedDecompressionMethods; // Iterate the returned encodings and wrap the response stream using the specified algorithm. diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs index c04da551..fb543a1c 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs @@ -87,6 +87,7 @@ public sealed class OpenIddictValidationSystemNetHttpOptions /// Note: while HTTP compression is never opted-in by default, encoded responses returned by servers /// that enforce content compression are still decoded. This property can be used to exclude specific /// algorithms (e.g to mitigate a vulnerability affecting one of the decoders used by the runtime). + /// DecompressionMethods.All can be used to allow all the algorithms supported by OpenIddict. /// public DecompressionMethods AllowedDecompressionMethods { get; set; } #if NET diff --git a/test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs b/test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs index dc304931..9a7e5607 100644 --- a/test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs +++ b/test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs @@ -75,6 +75,28 @@ public class OpenIddictClientSystemNetHttpHandlersTests Assert.Equal(SR.GetResourceString(SR.ID2211), context.ErrorDescription); } + [Theory] + [MemberData(nameof(SupportedEncodings))] + public async Task DecompressResponseContent_DecompressesContentWhenAllMethodsAreAllowed(string encoding, DecompressionMethods method) + { + // Arrange + using var response = CreateCompressedResponse(encoding); + + var context = new PrepareDeviceAuthorizationRequestContext( + CreateTransaction(Mock.Of>(), response)); + var handler = new DecompressResponseContent( + CreateOptions(DecompressionMethods.All)); + + // Act + await handler.HandleAsync(context); + + // Assert + Assert.True(DecompressionMethods.All.HasFlag(method)); + Assert.False(context.IsRejected); + Assert.Empty(response.Content.Headers.ContentEncoding); + Assert.Equal(Payload, await response.Content.ReadAsStringAsync()); + } + [Theory] [InlineData(false)] [InlineData(true)] diff --git a/test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs b/test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs index a5eeb19e..a45034a2 100644 --- a/test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs +++ b/test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs @@ -75,6 +75,28 @@ public class OpenIddictValidationSystemNetHttpHandlersTests Assert.Equal(SR.GetResourceString(SR.ID2211), context.ErrorDescription); } + [Theory] + [MemberData(nameof(SupportedEncodings))] + public async Task DecompressResponseContent_DecompressesContentWhenAllMethodsAreAllowed(string encoding, DecompressionMethods method) + { + // Arrange + using var response = CreateCompressedResponse(encoding); + + var context = new PrepareConfigurationRequestContext( + CreateTransaction(Mock.Of>(), response)); + var handler = new DecompressResponseContent( + CreateOptions(DecompressionMethods.All)); + + // Act + await handler.HandleAsync(context); + + // Assert + Assert.True(DecompressionMethods.All.HasFlag(method)); + Assert.False(context.IsRejected); + Assert.Empty(response.Content.Headers.ContentEncoding); + Assert.Equal(Payload, await response.Content.ReadAsStringAsync()); + } + [Theory] [InlineData(false)] [InlineData(true)]