undici vulnerable to Denial of Service via quadratic Cache-Control and Vary header parsing
Description
Impact
When the RFC 9111 cache interceptor (undici.interceptors.cache()) is in use, undici parses the server's Cache-Control and Vary response headers with an optional-whitespace trim helper (trimOWS) whose regular expression /^[\t ]+|[\t ]+$/g backtracks quadratically. A malicious or compromised origin that returns a header value with a long run of internal whitespace forces the client to spend O(N^2) CPU parsing a single, size-bounded response, synchronously blocking the Node.js event loop. The attacker sends roughly N bytes and the victim spends roughly N^2 time. At the default maxHeaderSize (16 KiB) one such response stalls the event loop for around 100 to 200 ms; applications that raise maxHeaderSize reach multi-second stalls, and concurrent responses serialize. The default fetch() and request path is not affected, because it trims response headers with a linear scanner. Only the cache interceptor's header parsing uses the vulnerable helper.
Patches
Fixed in undici 7.30.4 and 8.14.1. The optional-whitespace trimming now runs in linear time.
Workarounds
Do not compose the cache interceptor (undici.interceptors.cache()). The default request and fetch() paths are unaffected.