Skip to content

Enable post-quantum TLS on a Node.js HTTPS server

Run Node 22.20+ or 24.5+ and keep the X25519MLKEM768 hybrid preferred, with classical fallback for old clients.

Tested on Node 24.23.0, OpenSSL 3.5.9 Lab run 2026-12-05 5 min Requires Node.js 22.20+, 24.5+ or 25+ (bundles OpenSSL 3.5)

The fix

If you set ecdhCurve, put the hybrid group in its own first tuple. The / tells OpenSSL to prefer it, even when a client first sends only a classical key share. Node passes the string to OpenSSL as is, so the tuple syntax works.

server.mjs
import https from "node:https";
import { readFileSync } from "node:fs";

https.createServer({
  key: readFileSync("server.key"),
  cert: readFileSync("server.crt"),
  ecdhCurve: "X25519MLKEM768 / X25519:P-256:P-384",
}, app).listen(443);

The same ecdhCurve option works in tls.createServer and tls.createSecureContext.

Shortcut: on Node 22.20+ or 24.5+ with no ecdhCurve option, you already prefer post-quantum. Node's default ("auto") uses the OpenSSL default list, which does the same thing. Delete an old ecdhCurve line instead of adding one.

Check your Node first

node -p process.versions.openssl

You need 3.5 or newer. Node bundles its own OpenSSL, so the Node version decides, not the OS. On Node with OpenSSL 3.0, the line above makes the server fail at startup with Failed to set ECDH curve.

Official node image Node Bundled OpenSSL Ready?
node:20 20.20.2 3.0.19 No: upgrade Node
node:22.19 22.19.0 3.0.17 No
node:22.20 22.20.0 3.5.2 Yes
node:22 22.23.5 3.5.9 Yes
node:24.4 24.4.1 3.0.16 No
node:24.5 24.5.0 3.5.1 Yes
node:24 24.23.0 3.5.9 Yes
node:25 25.9.0 3.5.5 Yes
node:26 26.14.0 3.5.9 Yes

Checked by running each image (Alpine tags; the bookworm-slim tags of 20, 22, 24 and 25 show the same OpenSSL) on 2026-12-06. A Node from a Linux package may use the system OpenSSL instead; the command above tells you either way.

What the common configs actually do

Tested in Docker against five client offers, including the exact one browsers send. "Preferred" means the server asks for post-quantum even when the client led with a classical key share.

Config Post-quantum What browsers get
ecdhCurve: "X25519MLKEM768 / X25519:…" (this fix) Preferred X25519MLKEM768
No ecdhCurve on Node 24 (default "auto") Preferred X25519MLKEM768
ecdhCurve: "X25519MLKEM768:X25519:…" (no /) Supported, not preferred X25519MLKEM768
ecdhCurve: "X25519:P-256:P-384" (old hardening guides) Off X25519 (classical)
No ecdhCurve on Node 20 Off X25519 (classical)

"Supported, not preferred" looks the same in a browser today, but a client that leads with a classical key share gets classical encryption. Preferring post-quantum closes that gap.

A classical ecdhCurve list is a common reason a server on a new Node is still classical-only.

Verify

openssl s_client -connect example.com:443 -groups X25519MLKEM768 </dev/null 2>&1 | grep "Negotiated TLS1.3 group"
# Negotiated TLS1.3 group: X25519MLKEM768

Or rescan with PQ Scan: the Confidentiality axis should read PQ preferred.

Things that don't change

  • Your certificate stays the same (post-quantum certificates are not available for public websites yet).
  • Clients without post-quantum support still connect with X25519 or P-256.
  • If a CDN, load balancer or reverse proxy terminates TLS in front of Node, visitors see its TLS, not this config. Fix it there too.

Ask your AI about this fix

Copy the recipe as Markdown, or open it in an assistant that can read the page.