Skip to content

feat(JwtBearer): SafeWebCore.JwtBearer module - fail-fast/loud broken JWT authority + hardening - #4

Merged
MPCoreDeveloper merged 3 commits into
masterfrom
feature/safewebcore-jwtbearer
Sep 10, 2026
Merged

feat(JwtBearer): SafeWebCore.JwtBearer module - fail-fast/loud broken JWT authority + hardening#4
MPCoreDeveloper merged 3 commits into
masterfrom
feature/safewebcore-jwtbearer

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

SafeWebCore.JwtBearer

Optional companion module for SafeWebCore that makes a misconfigured or unreachable JWT authority fail loud before your users ever see a 401, plus optional token hardening.

Why

Fixes the exact scenario from dotnet/aspnetcore#67991 (reported by Stephan van Rooij / @svrooij, milestone .NET 12 Planning): a misspelled authority (\organisations\ vs \organizations) lets the app start normally while every request 401s silently.

What this adds

  • \JwtAuthorityValidationGuard\ (IHostedService): eagerly loads the OpenID Connect metadata at startup; HTTP 4xx = permanent -> Error log + optional fail-fast; transient = Warning, app starts.
  • \AddJwtBearerAuthorityValidation(...), \AddJwtBearerHardening(...), and the one-liner \AddSafeWebCoreJwtBearer(...).
  • Token hardening (opt-in): signed tokens (\�lg: none\ rejected), algorithm allow-list, typ-header checks, audience/issuer enforcement, max clock skew / token lifetime, jti/nbf/iat.
  • Runtime metadata logging: decorator around \IConfigurationManager\ (IdentityModel 8.19.2) logs metadata failures at Error/Warning during runtime.
  • Stephan's repro as test AND example: \ ests/.../StephanReproIntegrationTests.cs\ (fake HTTP, deterministic) + runnable \�xamples/JwtBearerDemo/\ (broken vs fixed).

Verification

  • \dotnet build SafeWebCore.slnx -c Release\ - clean (0 warnings, 0 errors)
  • \dotnet test SafeWebCore.slnx -c Release\ - 163/163 passed (incl. 33 new JwtBearer tests)
  • NuGet pack verified: README + icon + xml in \SafeWebCore.JwtBearer.1.0.0.nupkg\

SonarCloud

Waiting for the SonarCloud analysis on this PR (project \MPCoreDeveloper_SafeWebCore) - fixes will be applied until the Quality Gate is green, then this PR can be merged to master.

@sonarqubecloud

Copy link
Copy Markdown

@MPCoreDeveloper
MPCoreDeveloper merged commit a668b39 into master Sep 10, 2026
2 checks passed
@MPCoreDeveloper
MPCoreDeveloper deleted the feature/safewebcore-jwtbearer branch September 10, 2026 09:18
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.

1 participant