Skip to content

Update dependencies and improve authentication security#198

Merged
marcominerva merged 3 commits into
masterfrom
develop
Jun 11, 2026
Merged

Update dependencies and improve authentication security#198
marcominerva merged 3 commits into
masterfrom
develop

Conversation

@marcominerva

Copy link
Copy Markdown
Owner
  • Bump NuGet package versions across all projects
  • Use constant-time comparison for API key and password checks
  • Refactor authentication result handling for clarity
  • Change claims parameters to IEnumerable for flexibility
  • Improve issuer/audience validation logic in JwtBearerService
  • Remove explicit culture from Basic auth regex

Closes #196

- Bump NuGet package versions across all projects
- Use constant-time comparison for API key and password checks
- Refactor authentication result handling for clarity
- Change claims parameters to IEnumerable<Claim> for flexibility
- Improve issuer/audience validation logic in JwtBearerService
- Remove explicit culture from Basic auth regex

Closes #196
Copilot AI review requested due to automatic review settings June 11, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown

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 updates NuGet dependencies and strengthens authentication flows by improving claim handling (avoiding fixed-size claim collection mutations) and introducing constant-time comparisons for configured API key/basic credentials.

Changes:

  • Bumped OpenAPI/Swashbuckle and SimpleAuthenticationTools.Abstractions package versions across library and samples.
  • Refactored API Key / Basic auth handlers to use CryptographicOperations.FixedTimeEquals and to accept IEnumerable<Claim> (defensively materializing to a mutable list before updating claims).
  • Updated JwtBearerService token creation signature to IEnumerable<Claim> and adjusted issuer/audience validation toggles.

Reviewed changes

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

Show a summary per file
File Description
src/SimpleAuthentication/SimpleAuthentication.csproj Bumps OpenAPI + SimpleAuthenticationTools.Abstractions package versions.
src/SimpleAuthentication/JwtBearer/JwtBearerService.cs Changes claims parameter to IEnumerable<Claim>, materializes claims to list, and tweaks issuer/audience validation flags.
src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs Uses fixed-time comparisons for configured credentials; materializes claims to list before updating; removes regex culture.
src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs Uses fixed-time comparison for configured API keys; materializes claims to list before updating.
src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj Bumps SimpleAuthenticationTools.Abstractions and Swashbuckle.SwaggerGen.
samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj Bumps Swashbuckle.AspNetCore version.
samples/MinimalApis/JwtBearerSample/JwtBearerSample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
samples/MinimalApis/BasicAuthenticationSample/BasicAuthenticationSample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
samples/MinimalApis/ApiKeySample/Program.cs Updates validator sample to return claims array to validate fixed-size-claims handling.
samples/MinimalApis/ApiKeySample/ApiKeySample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
samples/Controllers/JwtBearerSample/JwtBearerSample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
samples/Controllers/BasicAuthenticationSample/BasicAuthenticationSample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
samples/Controllers/ApiKeySample/ApiKeySample.csproj Bumps OpenAPI + Swashbuckle.SwaggerUI versions.
README.md Normalizes “NuGet” capitalization in badge label.

Comment thread src/SimpleAuthentication/JwtBearer/JwtBearerService.cs
Comment thread src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs Outdated
Assign value.ToString() to a variable before comparing API keys, improving readability and preventing multiple ToString() calls during fixed-time equality checks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment on lines +60 to +61
var credential = credentials.FirstOrDefault(c => CryptographicOperations.FixedTimeEquals(MemoryMarshal.AsBytes(c.UserName.AsSpan()), MemoryMarshal.AsBytes(userName.AsSpan()))
&& CryptographicOperations.FixedTimeEquals(MemoryMarshal.AsBytes(c.Password.AsSpan()), MemoryMarshal.AsBytes(password.AsSpan())));
Comment thread src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs Outdated
Comment on lines +46 to +53
var providedApiKey = value.ToString();
var apiKey = apiKeys.FirstOrDefault(a => CryptographicOperations.FixedTimeEquals(MemoryMarshal.AsBytes(a.Value.AsSpan()), MemoryMarshal.AsBytes(providedApiKey.AsSpan())));

if (apiKey is null)
{

return AuthenticateResult.Fail("Invalid API Key");
}
Added RegexOptions.CultureInvariant to the [GeneratedRegex] attribute for BasicAuthorizationHeaderRegex. This change ensures consistent parsing of the Basic authentication header regardless of the current culture settings.
@marcominerva marcominerva merged commit 460bfd7 into master Jun 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.NotSupportedException on ClaimExtensions.Remove with fixed-size claim collection

2 participants