Repository navigation
feat(auth): verify ML-DSA-44 session tokens - #598
Conversation
- 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
|
- Decode the signature and flip one bit, so the tampered token always differs from the signed one
dorsha
left a comment
There was a problem hiding this comment.
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
dorsha
left a comment
There was a problem hiding this comment.
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.
- Turn a LinkageError while loading the configured public key into an invalid signing key error that names BouncyCastle 1.79
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).
/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 nokeysarray, for example an HTML page from an edge without the route). A 5xx, a network error or an emptykeysarray still fails the fetch, so the cached keys are kept. Cache and refresh behavior is unchanged.alg(JwkPublicKey), and a token whose headeralgdiffers from it is rejected.noneand HS* stay rejected by the allowlist. ML-DSA-44 is registered with jjwt as a customSecureDigestAlgorithm, so exp/nbf/skew handling is unchanged. A JWK without analgkeeps the current allowlist behavior.bcprov-jdk18on1.87, already a dependency (Java 8+), moved fromruntimetocompilescope. 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 (theLinkageErroris caught per key and in the key cache), so classical tokens keep verifying.x-descope-protocol-version: 2is sent only while the cached key set holds an ML-DSA-44 key, and never when a public key is configured.DESCOPE_PUBLIC_KEY) can also be an ML-DSA-44 AKP JWK.ServerCommonExceptionnow carries the response's HTTP status (getStatusCode(), 0 when not from a response), which the v2 fallback uses.No breaking changes:
SigningKeykeeps its previous all-args constructor. Tokens signed with an alg other than their key's JWKalg(for example PS256 against an RS256 key) are now rejected; Descope never issues such tokens.Tests
none, and HS256 keyed with the RSA public key are rejected.LinkageErrorduring a refresh keeps the cached keys and the cooldown.algonly 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.DESCOPE_PUBLIC_KEYvalidates ML-DSA-44 session tokens throughDescopeClient.alg: PS256.