Browse Source

Replace DecompressionMethods.All by ~DecompressionMethods.None

pull/2569/head
Kévin Chalet 2 weeks ago
parent
commit
2c49118f83
  1. 14
      shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
  2. 2
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
  3. 2
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs
  4. 2
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs
  5. 2
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs
  6. 4
      test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpBuilderTests.cs
  7. 4
      test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs
  8. 4
      test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpBuilderTests.cs
  9. 4
      test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs

14
shared/OpenIddict.Extensions/OpenIddictPolyfills.cs

@ -72,20 +72,6 @@ internal static class OpenIddictPolyfills
#endif
}
extension(DecompressionMethods)
{
#if !NET
/// <summary>
/// Use all compression-decompression algorithms.
/// </summary>
/// <remarks>
/// Note: the backing value (-1) is identical to the one used by the
/// <c>DecompressionMethods.All</c> member exposed by .NET Core 2.1 and higher.
/// </remarks>
public static DecompressionMethods All => (DecompressionMethods) (-1);
#endif
}
extension(HMACSHA256)
{
#if !NET

2
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs

@ -615,7 +615,7 @@ 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
// ~DecompressionMethods.None (which is equivalent to .All) 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;

2
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs

@ -89,7 +89,7 @@ public sealed class OpenIddictClientSystemNetHttpOptions
/// algorithms (e.g to mitigate a vulnerability affecting one of the decoders used by the runtime).
/// By default, all the algorithms supported by OpenIddict are allowed.
/// </remarks>
public DecompressionMethods AllowedDecompressionMethods { get; set; } = DecompressionMethods.All;
public DecompressionMethods AllowedDecompressionMethods { get; set; } = ~DecompressionMethods.None;
/// <summary>
/// Gets the user-defined actions used to amend the <see cref="HttpClient"/>

2
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs

@ -611,7 +611,7 @@ 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
// ~DecompressionMethods.None (which is equivalent to .All) 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;

2
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs

@ -89,7 +89,7 @@ public sealed class OpenIddictValidationSystemNetHttpOptions
/// algorithms (e.g to mitigate a vulnerability affecting one of the decoders used by the runtime).
/// By default, all the algorithms supported by OpenIddict are allowed.
/// </remarks>
public DecompressionMethods AllowedDecompressionMethods { get; set; } = DecompressionMethods.All;
public DecompressionMethods AllowedDecompressionMethods { get; set; } = ~DecompressionMethods.None;
/// <summary>
/// Gets the user-defined actions used to amend the <see cref="HttpClient"/>

4
test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpBuilderTests.cs

@ -66,7 +66,7 @@ public class OpenIddictClientSystemNetHttpBuilderTests
var options = GetOptions(services);
// Assert
Assert.Equal(DecompressionMethods.All, options.AllowedDecompressionMethods);
Assert.Equal(~DecompressionMethods.None, options.AllowedDecompressionMethods);
}
[Theory]
@ -78,7 +78,7 @@ public class OpenIddictClientSystemNetHttpBuilderTests
[InlineData(DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.All)]
[InlineData(~DecompressionMethods.None)]
#endif
public void SetAllowedDecompressionMethods_SetsAllowedDecompressionMethods(DecompressionMethods methods)
{

4
test/OpenIddict.Client.SystemNetHttp.Tests/OpenIddictClientSystemNetHttpHandlersTests.cs

@ -85,13 +85,13 @@ public class OpenIddictClientSystemNetHttpHandlersTests
var context = new PrepareDeviceAuthorizationRequestContext(
CreateTransaction(Mock.Of<ILogger<OpenIddictClientDispatcher>>(), response));
var handler = new DecompressResponseContent<PrepareDeviceAuthorizationRequestContext>(
CreateOptions(DecompressionMethods.All));
CreateOptions(~DecompressionMethods.None));
// Act
await handler.HandleAsync(context);
// Assert
Assert.True(DecompressionMethods.All.HasFlag(method));
Assert.True((~DecompressionMethods.None).HasFlag(method));
Assert.False(context.IsRejected);
Assert.Empty(response.Content.Headers.ContentEncoding);
Assert.Equal(Payload, await response.Content.ReadAsStringAsync());

4
test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpBuilderTests.cs

@ -66,7 +66,7 @@ public class OpenIddictValidationSystemNetHttpBuilderTests
var options = GetOptions(services);
// Assert
Assert.Equal(DecompressionMethods.All, options.AllowedDecompressionMethods);
Assert.Equal(~DecompressionMethods.None, options.AllowedDecompressionMethods);
}
[Theory]
@ -78,7 +78,7 @@ public class OpenIddictValidationSystemNetHttpBuilderTests
[InlineData(DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli)]
[InlineData(DecompressionMethods.All)]
[InlineData(~DecompressionMethods.None)]
#endif
public void SetAllowedDecompressionMethods_SetsAllowedDecompressionMethods(DecompressionMethods methods)
{

4
test/OpenIddict.Validation.SystemNetHttp.Tests/OpenIddictValidationSystemNetHttpHandlersTests.cs

@ -85,13 +85,13 @@ public class OpenIddictValidationSystemNetHttpHandlersTests
var context = new PrepareConfigurationRequestContext(
CreateTransaction(Mock.Of<ILogger<OpenIddictValidationDispatcher>>(), response));
var handler = new DecompressResponseContent<PrepareConfigurationRequestContext>(
CreateOptions(DecompressionMethods.All));
CreateOptions(~DecompressionMethods.None));
// Act
await handler.HandleAsync(context);
// Assert
Assert.True(DecompressionMethods.All.HasFlag(method));
Assert.True((~DecompressionMethods.None).HasFlag(method));
Assert.False(context.IsRejected);
Assert.Empty(response.Content.Headers.ContentEncoding);
Assert.Equal(Payload, await response.Content.ReadAsStringAsync());

Loading…
Cancel
Save