Skip to content
Broken by quantumjwt-es256

JWT signed with ES256 / EdDSA

JSON Web Tokens signed with ECDSA (ES256/ES384) or EdDSA.

Why it's at risk

The signing key is an elliptic-curve key, which Shor's algorithm breaks; an attacker could forge tokens once a quantum computer exists. Plan to move to the ML-DSA JOSE algorithms from RFC 9964 as your identity provider and libraries add support, and keep algorithm choice in configuration rather than code.

Used for
Signature
Family
Token signature (elliptic curve)
Classical security
128 bits
Against a quantum computer
Broken
Standards
RFC 7518 (JWA), RFC 8037, RFC 7519 (JWT)
Read the guideMigration playbook

Migration guides

Concrete code changes to move off JWT signed with ES256 / EdDSA. Pick your stack.

JOSE / JWT libraries (e.g. jose) · javascriptJWT/JOSE: what the post-quantum state is, and how to get ready without breaking loginsExperimental

Why

JWTs signed with RS256/PS256 or ES256/EdDSA can be forged once a large quantum computer can recover the issuer's private key from its published JWKS. Tokens are short-lived, so this is not a harvest-now-decrypt-later problem: the deadline is "before such a machine exists", not today. But identity systems are slow to change, so preparation pays off.

State of standards (late 2026):

  • RFC 9964 ("ML-DSA for JOSE and COSE", 2026) registers the JWS algorithms ML-DSA-44, ML-DSA-65 and ML-DSA-87 and a new JWK key type AKP (Algorithm Key Pair).
  • Composite (hybrid) ML-DSA + ECDSA/EdDSA signatures for JOSE/COSE are still an IETF draft (draft-ietf-jose-pq-composite-sigs).
  • Library support is emerging. For example, the jose npm package supports the ML-DSA JWS identifiers since v6.1.0 where the JavaScript runtime's WebCrypto implements ML-DSA. Most identity providers, API gateways and OIDC client libraries do not yet issue or accept ML-DSA tokens.

Steps

  1. Inventory issuers and verifiers: npx -y pqe-cli scan . flags RS*/ES*/HS* usage. List every service that validates your tokens.
  2. Make algorithms configuration, not code. Verifiers should take an allow-list of algorithms and fetch keys from a JWKS by kid. Never accept alg blindly from the token header (RFC 8725).
  3. Practise key rotation now (publish a new kid, sign with it, retire the old one). The PQ migration is a rotation where the new key has a new algorithm.
  4. First-party tokens: if the issuer and verifier are the same organisation and can share a secret, HS256 with a random 256-bit secret is already quantum-safe.
  5. Pilot ML-DSA where both ends are yours: add ML-DSA-65 (or ML-DSA-44 if size matters) to verifier allow-lists, publish an AKP key in the JWKS, then switch signing.
  6. Third-party IdPs (Auth0/Okta/Entra/Cognito/Keycloak...): track their roadmaps; keep your verifiers ready to accept new algorithms.

Before

js
import { SignJWT, jwtVerify, createRemoteJWKSet } from 'jose';

const token = await new SignJWT({ sub: 'user-1' })
  .setProtectedHeader({ alg: 'RS256', kid: 'rsa-2024' })
  .setExpirationTime('15m')
  .sign(rsaPrivateKey);

const JWKS = createRemoteJWKSet(new URL('https://issuer.example/.well-known/jwks.json'));
await jwtVerify(token, JWKS); // accepts whatever alg the key allows

After (agile verifier; ML-DSA where supported)

js
import { SignJWT, jwtVerify, createRemoteJWKSet, generateKeyPair } from 'jose';

// Verifier: explicit allow-list that can grow without a code change
const ALLOWED = (process.env.JWT_ALGS ?? 'RS256,ML-DSA-65').split(',');
const JWKS = createRemoteJWKSet(new URL('https://issuer.example/.well-known/jwks.json'));
const { payload } = await jwtVerify(token, JWKS, { algorithms: ALLOWED, issuer: 'https://issuer.example' });

// Issuer (pilot): requires a jose version and runtime with ML-DSA support (e.g. recent Node 24+)
const { privateKey } = await generateKeyPair('ML-DSA-65');
const pqToken = await new SignJWT({ sub: 'user-1' })
  .setProtectedHeader({ alg: 'ML-DSA-65', kid: 'mldsa-2026' })
  .setExpirationTime('15m')
  .sign(privateKey);

Gotchas

  • Size. An ML-DSA-65 signature is 3,309 bytes, about 4.4 KB once base64url-encoded, against 342 characters for RS256. Tokens in cookies (4 KB browser limit per cookie) or HTTP headers (proxies often cap total headers at 8-16 KB) may break. ML-DSA-44 is smaller (2,420-byte signatures) but still large; consider reference tokens or token exchange at the edge.
  • JWKS size grows too: an ML-DSA-65 public key is 1,952 bytes.
  • Do not invent algorithm names. Use the registered ML-DSA-44/65/87 identifiers from RFC 9964; pre-RFC drafts used other names and key types.
  • Encrypted JWTs (JWE) with RSA-OAEP or ECDH-ES key management are a harvest-now-decrypt-later risk if tokens carry sensitive data and are stored; prefer not putting secrets in tokens, or plan PQ key management once standardised for JOSE.
  • HS256 pitfalls: weak or shared-everywhere secrets, and algorithm-confusion bugs; follow RFC 8725.

Verify

Decode a token header (echo $TOKEN | cut -d. -f1 | base64 -d) to see alg and kid, run your verifier tests with both the classical and the ML-DSA key in the JWKS, and measure the largest token size against your cookie and header limits.

any (design pattern) · typescriptCrypto-agility: put cryptography behind an interface so the post-quantum swap is a config changeProduction-ready

Why

Most of the cost of a cryptographic migration is not the new algorithm, it is finding and changing every place that hard-codes the old one: RSA.generate(2048) in five services, signatures stored without saying which algorithm made them, database columns sized for 256-byte signatures. Crypto-agility means you can change algorithms through configuration and a rollout, not a rewrite. NIST's guidance on the post-quantum transition (NIST IR 8547, and its crypto-agility work in CSWP 39) treats it as a core requirement because more transitions will follow.

The pattern

  1. One module owns cryptography. Application code calls seal(), open(), sign(), verify(), never a library primitive directly.
  2. Every output is self-describing. Ciphertexts, signatures and keys carry an algorithm identifier (and key ID) in a versioned envelope.
  3. Verifiers/decryptors accept a set; producers use one. Readers support old and new algorithms during the transition; writers switch by configuration.
  4. Keys are looked up by ID from a key store or KMS, so rotating keys and algorithms is the same operation.
  5. Sizes are not assumed. Storage and protocols allow kilobyte-sized keys, ciphertexts and signatures.

Before

ts
import { sign as edSign, createPrivateKey } from 'node:crypto';

// Algorithm and key format hard-coded at every call site; signature stored bare.
const sig = edSign(null, payload, createPrivateKey(process.env.SIGNING_KEY!));
await db.insert({ payload, sig: sig.toString('base64') });

After

ts
// crypto/signer.ts: the only file that knows algorithms.
import { sign, verify, KeyObject } from 'node:crypto';

export type SigAlg = 'Ed25519' | 'ML-DSA-65';
export interface SignedEnvelope { v: 1; alg: SigAlg; kid: string; sig: string } // base64

interface KeyRecord { kid: string; alg: SigAlg; privateKey?: KeyObject; publicKey: KeyObject }

export class Signer {
  constructor(
    private readonly keys: Map<string, KeyRecord>,
    private readonly activeKid: string,          // from configuration
    private readonly acceptAlgs: Set<SigAlg>,    // from configuration
  ) {}

  sign(data: Buffer): SignedEnvelope {
    const k = this.keys.get(this.activeKid)!;
    // Ed25519 and ML-DSA both take a null digest in node:crypto (ML-DSA: Node 24.6+)
    return { v: 1, alg: k.alg, kid: k.kid, sig: sign(null, data, k.privateKey!).toString('base64') };
  }

  verify(data: Buffer, env: SignedEnvelope): boolean {
    if (!this.acceptAlgs.has(env.alg)) return false;
    const k = this.keys.get(env.kid);
    if (!k || k.alg !== env.alg) return false;   // never trust alg without the key's own record
    return verify(null, data, k.publicKey, Buffer.from(env.sig, 'base64'));
  }
}

// Call sites never mention an algorithm:
const env = signer.sign(payload);
await db.insert({ payload, signature: JSON.stringify(env) });   // TEXT/JSONB column, not VARCHAR(100)

Migration then becomes: deploy verifiers with acceptAlgs = {Ed25519, ML-DSA-65} → add an ML-DSA key → switch activeKid → re-sign or expire old data → drop Ed25519 from acceptAlgs.

Gotchas

  • Do not let the message choose the algorithm. The verifier must check that the key ID's registered algorithm matches the envelope (JWT "alg confusion" bugs come from skipping this).
  • Downgrade protection. Once everything supports the new algorithm, remove the old one from the accept list; otherwise attackers who can forge the old one still win.
  • Hybrid/dual signatures (both classical and PQ) fit the same envelope: alg: 'Ed25519+ML-DSA-65' with two signatures, verified with AND semantics.
  • Inventory first. You can't wrap what you haven't found: npx -y pqe-cli scan . --cbom -o cbom.json produces a CycloneDX cryptography bill of materials to track progress.
  • Sizes: ML-DSA-65 signatures are 3,309 bytes; ML-KEM-768 ciphertexts 1,088 bytes. Use TEXT/BLOB/JSONB columns, and test message-size limits (queues, headers, cookies, MTU-sensitive UDP protocols).

Verify

Write a test that signs with one algorithm and verifies after flipping activeKid, and a test that an envelope claiming an algorithm not registered for its kid is rejected. Re-run npx -y pqe-cli scan . and confirm crypto primitives appear only in the crypto module.