Skip to content
jshacks.dev
Security

Check Whether Node Uses Post Quantum TLS Key Exchange

Find out which of your Node.js connections negotiate X25519MLKEM768, from one socket to every fetch call, and fail CI when post-quantum TLS drops.

9 min read
Summarize in AI
Flat illustration of a shield with a lock, a key and a password field, with the Node.js, OpenSSL, JSON Web Tokens and Let's Encrypt logos.

The NSA advisory of 2 December 2026 starts every migration with an inventory, and for a Node.js service the first line of that inventory is a plain question: which of its TLS connections are protected by post-quantum key exchange right now? The official Node.js 26.14.0 and 24.23.0 binaries bundle OpenSSL 3.5.9, which offers the hybrid group X25519MLKEM768 by default, so the honest answer is usually "some of them". Which ones depends on the far side of each connection, and on settings scattered through your code and dependencies.

Guessing is not good enough for an inventory. This post shows how to get the answer from Node.js itself: first for one socket, then for every outbound connection a running process makes, then as a check that fails a CI job when a connection that should be post-quantum is not. It is the measuring half of the post-quantum cryptography migration guide for Node, which covers the configuration side.

The one method that answers it

[tlsSocket.getEphemeralKeyInfo()](https://nodejs.org/docs/latest-v26.x/api/tls.html#tlssocketgetephemeralkeyinfo) returns the key exchange a client socket negotiated. For classical elliptic-curve groups the object has been the same for years: type: 'ECDH', the curve name, and its size in bits. The hybrid and ML-KEM groups are not elliptic curves, and for a long time the method did not know what to do with them. On a connection that used X25519MLKEM768 it returned an empty object, which issue #59452 reported in 2025.

The fix in pull request #64119 shipped in Node.js 26.5.0 and 24.19.0. On those releases and later, a post-quantum or hybrid group comes back as { type: 'TLSGroup', name: 'X25519MLKEM768' }, with no size field, because a bit size does not describe a hybrid. So the version matters before any other step:

Node.jsHybrid group reported as
26.5.0 and later, 24.19.0 and later{ type: 'TLSGroup', name: 'X25519MLKEM768' }
24.5.0 to 24.18.x, 26.0.0 to 26.4.x, 22.20.0 and later{}
Releases bundling OpenSSL 3.0never negotiated

Node.js 22 has the OpenSSL 3.5 behavior from 22.20.0 but not the reporting fix, so on 22.x an empty object is the hybrid group, by elimination. That is usable in a pinch and fragile in a script. Run audits on 26.x or 24.19 and later, even if the service itself still runs 22.

The method also returns null on a server-side socket. You cannot ask your own https.createServer() what a client negotiated this way; you check a server by connecting to it from a Node.js client, which the first script below does.

Checking one host

tls-group.mjsJavaScript
import tls from 'node:tls';

function check(host, port = 443) {
  return new Promise((resolve, reject) => {
    const socket = tls.connect({ host, port, servername: host, minVersion: 'TLSv1.3' }, () => {
      const info = socket.getEphemeralKeyInfo();
      socket.end();
      resolve({ host, protocol: socket.getProtocol(), group: info?.name ?? 'unknown' });
    });
    socket.setTimeout(5000, () => socket.destroy(new Error(`timeout: ${host}`)));
    socket.once('error', reject);
  });
}

for (const host of process.argv.slice(2)) {
  const { protocol, group } = await check(host);
  console.log(host.padEnd(22), protocol, group);
}

Pointed at a server on OpenSSL 3.5 with default settings and one that only speaks classical groups, Node.js 26.14.0 prints:

Text
pq.example.test        TLSv1.3 X25519MLKEM768
legacy.example.test    TLSv1.3 X25519

Three choices in that script are deliberate. minVersion: 'TLSv1.3' makes a TLS 1.2-only server fail loudly instead of quietly negotiating classical ECDHE, because the ML-KEM groups exist only in TLS 1.3. servername is set because without SNI many hosts serve a default certificate and sometimes a different TLS configuration. And info?.name ?? 'unknown' turns the pre-fix empty object into a visible word rather than undefined.

Use the hostnames your code actually connects to, including internal ones such as the database, the cache and the queue, not only public APIs. A PostgreSQL server needs a different client because it starts TLS after a protocol message, but pg itself exposes its socket; the next section covers clients you do not control.

Auditing every outbound connection in a running process

A service does not make one connection. It calls fetch(), an SDK built on undici, axios built on node:https, a gRPC client, a database driver. Pointing the script above at a list of hostnames you remember misses the ones you do not. The better source is the process itself.

Node.js's built-in fetch() is undici, and undici publishes diagnostics channels for its lifecycle. The undici:client:connected message carries the raw socket and the connection parameters, published once per new connection, not per request. That is exactly where to read the group:

pq-audit.mjsJavaScript
import diagnosticsChannel from 'node:diagnostics_channel';

const seen = new Map();

diagnosticsChannel.subscribe('undici:client:connected', ({ socket, connectParams }) => {
  if (connectParams.protocol !== 'https:' || typeof socket.getEphemeralKeyInfo !== 'function') return;
  const origin = `${connectParams.hostname}:${connectParams.port || 443}`;
  const group = socket.getEphemeralKeyInfo()?.name ?? 'unknown';
  seen.set(origin, group);
});

process.once('beforeExit', () => {
  for (const [origin, group] of seen) {
    const mark = group.includes('MLKEM') ? 'pq ' : 'NOT';
    console.log(mark, origin.padEnd(26), group);
  }
});

Load it before the application with node --import ./pq-audit.mjs server.mjs, exercise the service with its integration tests or a staging run, and stop it. For a run that reached one hybrid-capable API and one classical one, the output is:

Text
pq  api.pq.example.test:443    X25519MLKEM768
NOT legacy.example.test:443    X25519

The typeof guard is there because undici also opens plain TCP sockets for http: origins, and those have no TLS method. The Map keeps one line per origin however many requests went to it. beforeExit fires when the event loop empties, which suits a test run; a long-lived server would log from the subscriber instead, or expose the map on an admin endpoint.

Connections that do not go through undici

The undici channel sees fetch() and anything built on undici. It does not see node:https, so axios, got, gRPC and the database drivers stay invisible to it. For those, the most direct hook is the agent's own socket, which https.Agent emits through the request's socket event, or the secureConnect event of a tls.connect() socket. Node.js also publishes net.client.socket on the [node:diagnostics_channel built-in channels](https://nodejs.org/docs/latest-v26.x/api/diagnostics_channel.html#built-in-channels), with the socket that net.connect() created; on a TLS connection that is the underlying TCP socket and not the TLSSocket, so it tells you where the process connected but not what it negotiated. The practical approach for an audit is to wrap what you control:

audit-https.mjsJavaScript
import https from 'node:https';

export function watchAgent(agent, report) {
  const createConnection = agent.createConnection.bind(agent);
  agent.createConnection = (options, callback) => {
    const socket = createConnection(options, callback);
    socket.once('secureConnect', () => {
      report(options.servername ?? options.host, socket.getEphemeralKeyInfo()?.name ?? 'unknown');
    });
    return socket;
  };
  return agent;
}

watchAgent(https.globalAgent, (host, group) => console.log(host, group));

Called on https.globalAgent early in startup, it covers every https.request() that uses the default agent, which is what axios and got do unless they were given their own. A library with a private agent needs the same call on that agent. This is audit code: run it in staging or CI, not in production, because patching an agent's methods is the kind of thing a later Node.js release can change under you.

Turning the audit into a CI check

An inventory that is read once goes stale the day a dependency adds a new endpoint or someone pastes an old ecdhCurve into a config file. A CI job keeps it current. The idea is a list of origins that must be post-quantum, and a failed build when one is not:

pq-gate.mjsJavaScript
import { readFileSync } from 'node:fs';
import tls from 'node:tls';

const required = JSON.parse(readFileSync('pq-required.json', 'utf8'));

function group(host, port) {
  return new Promise((resolve) => {
    const socket = tls.connect({ host, port, servername: host, minVersion: 'TLSv1.3' }, () => {
      resolve(socket.getEphemeralKeyInfo()?.name ?? 'unknown');
      socket.end();
    });
    socket.setTimeout(5000, () => socket.destroy());
    socket.once('error', (err) => resolve(`error ${err.code ?? err.message}`));
  });
}

let failed = 0;
for (const { host, port = 443 } of required) {
  const name = await group(host, port);
  const ok = name.includes('MLKEM');
  if (!ok) failed += 1;
  console.log(ok ? 'ok  ' : 'FAIL', host, name);
}
process.exitCode = failed ? 1 : 0;

With pq-required.json holding [{"host":"pq.example.test"},{"host":"legacy.example.test"}], the job prints:

Text
ok   pq.example.test X25519MLKEM768
FAIL legacy.example.test X25519

and exits with status 1. Start the list with the origins you have already moved and add one each time a server is upgraded; a gate that fails on day one for every host gets switched off by day three.

Two details make the gate trustworthy. Run it on the same Node.js image as production, because a CI runner with a distro Node.js linked to OpenSSL 3.0 will never offer the hybrid group and will fail every host for a reason that has nothing to do with the servers. And add one line at the top that refuses to run on a release older than 26.5.0 or 24.19.0, so an empty object from an old runtime cannot look like a classical result.

Reading a classical result

When a connection reports X25519, the cause is on one of three sides, and the scripts above tell you which by comparison.

  • The client did not offer it. Run tls-group.mjs against a host known to support the hybrid group, such as one you upgraded yourself. If that also prints X25519, the problem is in your process: an OpenSSL 3.0 build (check process.versions.openssl), or an ecdhCurve or tls.DEFAULT_ECDH_CURVE override listing only classical curves. The second is the common one, because it never produces an error.

  • The server does not support it. If the reference host prints X25519MLKEM768 and the target prints X25519, the server or the proxy in front of it is the gap. That goes in the inventory as the owner's problem, with the date you checked.

  • Something between you dropped it. If the target times out with the hybrid group and connects with ecdhCurve: 'X25519', a middlebox is probably choking on the larger ClientHello. The OpenSSL documentation describes this and the ?X25519MLKEM768:DEFAULT workaround that keeps the group available without sending its key share first.

PostgreSQL deserves its own note. [PostgreSQL 18's ssl_groups](https://www.postgresql.org/docs/18/runtime-config-connection.html) defaults to X25519:prime256v1, so a modern Node.js client and a modern PostgreSQL server negotiate X25519 until the server's configuration names the hybrid group. If your audit shows every service post-quantum except the database, that is why.

What a clean audit does and does not prove

A row of X25519MLKEM768 means the session keys of those connections cannot be recovered later from a recording by a quantum computer, which is the harvest now, decrypt later risk the advisory leads with. It says nothing about the certificates, which are still RSA or ECDSA and will be for a while: certificate signatures matter only at the moment of the handshake, so they are a later and separate migration. And it says nothing about the data you store, which an attacker who reaches your database can read whatever the transport did.

It also only covers what the audit saw. A code path that runs once a month, a webhook that fires on a rare event, a cron job in another container: each one needs to be exercised during the audit run or listed in the gate by hand.

Also inNode.js
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.