undici vulnerable to Denial of Service via TLS 1.2 certificate-changing renegotiation
Affected releases · undici
- 8.x8.0.0 – 8.12.1Fixed in 8.12.2
- 7.x7.0.0 – 7.30.0Fixed in 7.30.1
- 6.x6.0.0 – 6.29.0Fixed in 6.29.1
- 5.x and older4.2.1 – 5.29.0No fix, no longer updated
On 8.x, the newest line:
npm install undici@8.12.2Every release on a timeline
Affected
8.0.0 – 8.12.1
22 releases
Fixed
8.12.2 – 8.13.1
5 releases
Affected
7.0.0 – 7.30.0
50 releases
Fixed
7.30.1 – 7.30.2
2 releases
Affected
6.0.0 – 6.29.0
56 releases
Fixed
6.29.1
1 release
Affected
5.0.0 – 5.29.0
59 releases
Not affected
4.0.0 – 4.2.0
4 releases
Affected
4.2.1 – 4.16.0
45 releases
What happens
Impact
undici crashes the client process when a TLS 1.2 server renegotiates after the connection is established and presents a different, CA-trusted certificate whose hostname does not match the requested host. Node.js re-runs hostname verification on the renegotiated handshake and destroys the socket with ERR_TLS_CERT_ALTNAME_INVALID. undici's established socket error handler asserted that this error code could never occur, so the peer-controlled error became an uncaught AssertionError that terminates the Node.js process. Both the HTTP/1.1 and HTTP/2 paths are affected.
A malicious or compromised HTTPS endpoint reached through undici or the global fetch() can crash the client with a single server-initiated renegotiation, taking down all in-flight requests and background work in the process. Only TLS 1.2 is affected, because TLS 1.3 does not support renegotiation. Exploitation does not require a CA compromise: the attacker controls the endpoint and can present two ordinary valid certificates, the first matching the requested URL and the second intentionally not matching it.
Patches
Upgrade to undici 6.29.1, 7.30.1, or 8.12.2.
Workarounds
Restrict outbound connections to TLS 1.3, for example by setting connect: { minVersion: 'TLSv1.3', maxVersion: 'TLSv1.3' } on the client or agent, so that renegotiation cannot occur, when the target endpoints support TLS 1.3.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.