readTlsClientHello fails when ClientHello spans multiple TLS records
readTlsClientHello (and getTlsFingerprintAsJa3, getTlsFingerprintAsJa4, and trackClientHellos) fails with Unexpected client hello length when a valid ClientHello handshake message is fragmented across multiple TLS records (RFC 8446 section 5.1), such as from record-splitting clients/proxies or large post-quantum ClientHellos.
Reproduction (npm install [email protected] && node repro.mjs):
// repro.mjs
import { readTlsClientHello } from "read-tls-client-hello";
import { PassThrough } from "node:stream";
import net from "node:net";
import tls from "node:tls";
const hello = await new Promise((resolve) => {
const srv = net.createServer((s) => {
s.once("data", (d) => {
resolve(d);
s.destroy();
srv.close();
});
});
srv.listen(0, () => {
const c = tls.connect({ port: srv.address().port, servername: "example.com" });
c.on("error", () => {});
});
});
const body = hello.subarray(5, 5 + hello.readUInt16BE(3));
const record = (b) =>
Buffer.concat([Buffer.from([0x16, 0x03, 0x01, b.length >> 8, b.length & 0xff]), b]);
const split = Buffer.concat([record(body.subarray(0, 100)), record(body.subarray(100))]);
for (const [name, bytes] of [["one record", hello], ["two records", split]]) {
const s = new PassThrough();
s.end(bytes);
try {
const h = await readTlsClientHello(s);
console.log(`${name} -> ${h.cipherSuites.length} cipher suites, ${h.extensions.length} extensions`);
} catch (e) {
console.log(`${name} -> ${e.name}: ${e.message}`);
}
}
Actual output:
one record -> 52 cipher suites, 11 extensions
two records -> Error: Unexpected client hello length: 1579 (of 100)
Expected: two records parses the same 52 cipher suites and 11 extensions as one record (Node's tls.Server completes the handshake normally when given the two-record form, while trackClientHellos logs a warning and leaves socket.tlsClientHello undefined).
Versions tested: [email protected] from npm and main at e67df7c, on Node v26.13.0 (Linux x64).
In src/index.ts, extractTlsHello reads only a single 0x16 TLS record (5 + recordLength bytes) instead of reassembling consecutive 0x16 records until the 3-byte handshake length in readTlsClientHello is satisfied.
Credit: https://ucsbplse.github.io/
The X25519MLKEM768 key share makes the ClientHello about 1.2 KB larger, so it often spans two TCP segments or TLS records. Middleboxes, firewalls or parsers that expect it in one packet drop or reset the connection; updating that device, or temporarily offering X25519 alone, confirms the cause.
Step-by-step guide: https://ather-quantum.com/guides/enable-x25519mlkem768-nginx To verify from outside (which group the server actually negotiates): https://ather-quantum.com/?domain=yourdomain
(Disclosure: I run that scanner; the guide and the check are free.)