Skip to content

feat(auth): verify ML-DSA-44 session tokens - #598

Merged
omercnet merged 4 commits into
mainfrom
feat/mldsa-44-session-verify
Dec 5, 2026
Merged

omercnet merged 4 commits into
mainfrom
feat/mldsa-44-session-verify

Conversation

@omercnet

@omercnet omercnet commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Related Issues

https://github.com/descope/etc/issues/21341 (umbrella https://github.com/descope/etc/issues/21167)

Release only after the backend serves ML-DSA-44 keys on /v3/keys in all regions.

Description

Verifies ML-DSA-44 (FIPS 204, RFC 9964 JOSE) session tokens, matching go-sdk (#957, #960, #961, #962) and node-sdk (#847, #848).

  • Keys: fetches /v3/keys/<projectId>, which also serves AKP (alg: ML-DSA-44) keys, and falls back to /v2/keys/<projectId> on a 404 or a 2xx body that isn't a key set (invalid JSON or no keys array, for example an HTML page from an edge without the route). A 5xx, a network error or an empty keys array still fails the fetch, so the cached keys are kept. Cache and refresh behavior is unchanged.
  • Verify: a key is bound to its JWK alg (JwkPublicKey), and a token whose header alg differs from it is rejected. none and HS* stay rejected by the allowlist. ML-DSA-44 is registered with jjwt as a custom SecureDigestAlgorithm, so exp/nbf/skew handling is unchanged. A JWK without an alg keeps the current allowlist behavior.
  • Crypto: BouncyCastle bcprov-jdk18on 1.87, already a dependency (Java 8+), moved from runtime to compile scope. Its provider instance is used directly and never added to the JVM's provider list. ML-DSA needs 1.79 or later (documented in the README); if an application pins an older version, ML-DSA-44 keys are skipped with a warning (the LinkageError is caught per key and in the key cache), so classical tokens keep verifying.
  • Protocol header: x-descope-protocol-version: 2 is sent only while the cached key set holds an ML-DSA-44 key, and never when a public key is configured.
  • Cookies: the Java SDK never sets or forwards the session token as a cookie, so there is nothing to change there.
  • The configured public key (DESCOPE_PUBLIC_KEY) can also be an ML-DSA-44 AKP JWK.
  • ServerCommonException now carries the response's HTTP status (getStatusCode(), 0 when not from a response), which the v2 fallback uses.

No breaking changes: SigningKey keeps its previous all-args constructor. Tokens signed with an alg other than their key's JWK alg (for example PS256 against an RS256 key) are now rejected; Descope never issues such tokens.

Tests

  • An ML-DSA-44 token signed with a key generated in the test verifies; a tampered or expired one is rejected.
  • A mismatched alg (PS256, RS384 against an RS256 JWK; ML-DSA-44 and RS256 tokens with each other's kid), none, and HS256 keyed with the RSA public key are rejected.
  • AKP keys for another alg or of the wrong size are skipped, and so are ML-DSA-44 keys when BouncyCastle lacks ML-DSA; a LinkageError during a refresh keeps the cached keys and the cooldown.
  • A JWK without an alg only verifies its own key type: an ML-DSA-44 token is refused by an alg-less RSA key, and an RS256 token by a configured ML-DSA-44 key.
  • A configured ML-DSA-44 DESCOPE_PUBLIC_KEY validates ML-DSA-44 session tokens through DescopeClient.
  • v3 404 and v3 HTML both fall back to v2 and verify RS256; a v3 5xx or empty key set doesn't fall back.
  • The header is sent only with an ML-DSA key cached, and never with a configured key.
  • Existing classical tests unchanged, except the PS256 test now publishes its JWK with alg: PS256.

- Fetch /v3/keys, falling back to /v2/keys on a 404 or a 2xx body that isn't a key set
- Bind each key to its JWK alg and reject tokens signed with another alg
- Verify ML-DSA-44 (RFC 9964) with BouncyCastle, registered as a jjwt algorithm
- Send x-descope-protocol-version 2 only while an ML-DSA-44 key is cached and no public key is configured

Refs descope/etc#21341
@omercnet
omercnet marked this pull request as ready for review December 5, 2026 18:42
@shuni-bot

shuni-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Shuni Shuni Review

No new issues found.

Approval outcome: APPROVED
Reason: Cumulative full review completed across trusted review history with no findings and clear review threads.

Model: claude-opus-5.5 · Effort: medium


Review scope: Partial incremental re-review

Reviewed new changes (3)
  • README.md
  • src/main/java/com/descope/client/DescopeClient.java
  • src/test/java/com/descope/sdk/auth/impl/KeyProviderTest.java
Previously reviewed and unchanged: 11 files.

Shuni Review complete — View session on Shuni Portal Shuni

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shuni Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

- Decode the signature and flip one bit, so the tampered token always differs from the signed one
shuni-bot[bot]
shuni-bot Bot previously approved these changes Dec 5, 2026

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shuni Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@dorsha dorsha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Design matches go-sdk: keys pinned to their JWK alg, none/HS* still excluded, ML-DSA-44 plugged in as a jjwt digest algorithm so exp/nbf checks still apply, BC used without registering a JVM provider, v3 to v2 fallback only on 404 or a non-keyset 2xx, header only while an ML-DSA key is cached. One blocker inline (older BouncyCastle on the customer classpath), plus a test gap.

Also, the PR description says release after the backend is live in "prod, star and FedStart". This repo is public, so please use something like "after the backend serves ML-DSA-44 keys on /v3/keys in all regions".

- Catch LinkageError per key, so an older bcprov on the classpath skips ML-DSA-44 keys instead of breaking classical verification
- Record the failed attempt on a LinkageError in Client.getKey so the refetch cooldown applies
- Document BouncyCastle 1.79 as the minimum for ML-DSA-44
- Test alg-less keys against the other key type and a configured ML-DSA-44 public key
@omercnet

omercnet commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

@dorsha thanks. 9c882ea catches the LinkageError per key and in the key cache, documents BouncyCastle 1.79 as the minimum, and adds the alg-less and configured-AKP-key tests. The description now says to release after the backend serves ML-DSA-44 keys on /v3/keys in all regions.

@omercnet
omercnet requested a review from dorsha December 5, 2026 19:01
dorsha
dorsha previously approved these changes Dec 5, 2026

@dorsha dorsha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-checked 9c882ea: LinkageError is now caught per key (AKP skipped with a BouncyCastle 1.79+ warning) and in Client.getKey (attempt recorded, cooldown applies), with tests for both. The alg-less RSA JWK and configured ML-DSA public key cases are covered, the duplicate import is gone, and the README states the 1.79 minimum. The description no longer names internal environments. LGTM.

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shuni Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Comment thread README.md Resolved
- Turn a LinkageError while loading the configured public key into an invalid signing key error that names BouncyCastle 1.79

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shuni Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@dorsha dorsha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-checked 1aab595: a configured ML-DSA public key on BouncyCastle older than 1.79 now fails client creation with a clear message instead of a raw LinkageError, with a test, and the README says so. Still LGTM.

@omercnet
omercnet merged commit 8a899dd into main Dec 5, 2026
19 checks passed
@omercnet
omercnet deleted the feat/mldsa-44-session-verify branch December 5, 2026 19: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.

3 participants