Skip to content

fix: validate refresh token signature and type - #31

Merged
brunobritodev merged 4 commits into
masterfrom
fix/refresh-token-validation
Nov 18, 2026
Merged

brunobritodev merged 4 commits into
masterfrom
fix/refresh-token-validation

Conversation

@brunobritodev

Copy link
Copy Markdown
Member

Summary

Security patch for the 8.x line (net8.0 / net10.0). It should release 8.0.1. The same fix is also applied to the .NET 10 upgrade in #30.

ValidateRefreshToken hardening

  • Requires a signed token. Validation used RequireSignedTokens = false.
  • Requires the rt+jwt token type, so an access token (at+jwt) is no longer accepted as a refresh token. Every refresh token issued since 6.1.0 already has this type.
  • Validates against the keys that can actually have signed the token: the configured SecretKey, or the last keys of the JWKS store. Before, only the current key was used, so refresh tokens stopped working after a key rotation and never worked in SecretKey mode.
  • Uses the same issuer logic as token creation.
  • A deleted user now returns IsValid = false ("User not found") instead of throwing NullReferenceException.
  • Lockout check fixed. It used LockoutEnd < DateTime.Now, so it blocked users whose lockout had already ended and let locked-out users through. It now uses UserManager.IsLockedOutAsync.
  • Uses the async JsonWebTokenHandler.ValidateTokenAsync; the sync method is obsolete.

Vulnerable dependencies

  • Pins the patched versions of System.Security.Cryptography.Xml/Pkcs: 8.0.5/8.0.2 on net8.0 and 10.0.15 on net10.0. The previous versions had high severity advisories, coming in through DataProtection and NetDevPack.Security.Jwt.
  • Microsoft.* 8.0.34 / 10.0.15, System.IdentityModel.Tokens.Jwt 8.23.0.

Tests (new)

tests/NetDevPack.Identity.Tests (xunit.v3 on Microsoft.Testing.Platform, enabled via global.json) runs on net8.0 and net10.0.

  • RefreshTokenSecurityTests covers: a valid token, an unsigned token, a token signed by an unknown key, an access token used as a refresh token, malformed tokens, a locked-out user, an expired lockout, and a deleted user.
  • Five of these tests fail against the current master code.
  • JwtBuilderTests covers access token claims and signature, user lookup by id/username/email, and one-time refresh tokens.

Test plan

  • dotnet test -c Release: 28/28 passed (14 tests × net8.0/net10.0), three runs in a row
  • Same security tests against the unpatched JwtBuilderInject: 5 failures (expected)
  • dotnet list package --vulnerable --include-transitive: no vulnerable packages

Recommendation

After 8.0.1 is published, consider publishing a GitHub Security Advisory for versions ≤ 8.0.0 so dependents are notified.

ValidateRefreshToken now:
- requires a signed token (RequireSignedTokens was false)
- requires the rt+jwt token type, so an access token is not accepted
- validates against the configured SecretKey or the last JWKS keys
- uses the same issuer logic as token creation
- rejects tokens of deleted users instead of throwing
- uses UserManager.IsLockedOutAsync (the lockout check was inverted)
- uses the async JsonWebTokenHandler.ValidateTokenAsync

Adds NetDevPack.Identity.Tests (net8.0/net10.0) with regression tests.
Pin System.Security.Cryptography.Xml/Pkcs (8.0.5/8.0.2 on net8.0, 10.0.15 on net10.0), Microsoft.* 8.0.34/10.0.15, System.IdentityModel.Tokens.Jwt 8.23.0.
brunobritodev added a commit that referenced this pull request Nov 17, 2026
Same fix as #31 (8.x): signed rt+jwt tokens only, last JWKS keys or SecretKey, same issuer logic as creation, deleted users rejected, lockout check fixed (IsLockedOutAsync), async validation. Adds RefreshTokenSecurityTests.
The package exists to issue tokens that other services validate through JWKS.
JwksIntegrationTests starts a host with UseJwksDiscovery and checks that:
- /jwks publishes public keys only
- a third party validates the access token with only the published JWKS
- refresh tokens are signed with the JWKS key and still validate

Test parallelization is disabled: PersistKeysInMemory() uses a static store
shared by every host in the process and /jwks publishes only the last keys.
brunobritodev added a commit that referenced this pull request Nov 17, 2026
Same JwksIntegrationTests as #31: /jwks publishes public keys only, a third party validates the access token with the published JWKS, refresh tokens are signed with the JWKS key. Test parallelization disabled (static in-memory key store).
@brunobritodev
brunobritodev merged commit 811df9a into master Nov 18, 2026
2 checks passed
@brunobritodev
brunobritodev deleted the fix/refresh-token-validation branch November 18, 2026 01:01
github-actions Bot pushed a commit that referenced this pull request Nov 18, 2026
## [8.0.1](v8.0.0...v8.0.1) (2026-11-18)

### Bug Fixes

* validate refresh token signature and type ([#31](#31)) ([811df9a](811df9a))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.0.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

brunobritodev added a commit that referenced this pull request Nov 18, 2026
* feat!: target .NET 10 and update dependencies

- Target net10.0 only (drop net8.0; remove dead net7.0 conditions)
- NetDevPack.Security.Jwt.AspNetCore 8.2.2 -> 10.0.0, Microsoft.* 10.0.15,
  System.IdentityModel.Tokens.Jwt 8.23.0; pin patched
  System.Security.Cryptography.Xml/Pkcs 10.0.15 (high severity advisories)
- Central Package Management, NuGet Audit as errors, global.json, .editorconfig, dependabot
- Sample: Swashbuckle 7 -> 10.3.1 (Microsoft.OpenApi 2 security requirement API)
- Add NetDevPack.Identity.Tests (xunit.v3 + AwesomeAssertions): access token
  claims and signature, user lookup by id/username/email, one-time refresh tokens
- CI: actions/checkout v7, setup-dotnet v6; publish now restores, builds and
  tests before releasing; vulnerable package check; pack/push only on new release
- Package metadata: repository/project URL pointed to EduardoPires/NetDevPack,
  duplicated Authors, README now packed; LangVersion follows the SDK

BREAKING CHANGE: the package now targets .NET 10 only and depends on
NetDevPack.Security.Jwt 10. Stay on 8.x for .NET 8.

* fix: point package URLs to Security.Identity

* ci: use conventionalcommits release preset

* fix: validate refresh token signature and type

Same fix as #31 (8.x): signed rt+jwt tokens only, last JWKS keys or SecretKey, same issuer logic as creation, deleted users rejected, lockout check fixed (IsLockedOutAsync), async validation. Adds RefreshTokenSecurityTests.

* style: remove redundant parentheses

* test: cover JWKS issuance end to end

Same JwksIntegrationTests as #31: /jwks publishes public keys only, a third party validates the access token with the published JWKS, refresh tokens are signed with the JWKS key. Test parallelization disabled (static in-memory key store).
github-actions Bot pushed a commit that referenced this pull request Nov 18, 2026
## [9.0.0](v8.0.1...v9.0.0) (2026-11-18)

### ⚠ BREAKING CHANGES

* the package now targets .NET 10 only and depends on
NetDevPack.Security.Jwt 10. Stay on 8.x for .NET 8.

* fix: point package URLs to Security.Identity

* ci: use conventionalcommits release preset

* fix: validate refresh token signature and type

### Features

* target .NET 10 and update dependencies ([#30](#30)) ([9af62e2](9af62e2)), closes [#31](#31) [#31](#31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant