undici vulnerable to Denial of Service via unbounded cache memory from tiny response chunks
Description
Impact
undici's built-in cache stores, MemoryCacheStore and SqliteCacheStore, can be driven to exhaust process memory by a malicious or compromised HTTP origin. Both stores count response body bytes against their byte limits, but hold each delivered body chunk as a separate Buffer: MemoryCacheStore keeps the chunks in the cached entry, and SqliteCacheStore keeps them in memory until the response completes and is written to the database. A cacheable response framed as a large number of tiny chunks, for example a one million byte body sent as one million legal one-byte HTTP/1.1 chunks, holds one Buffer object per chunk, and that per-object overhead (over 100 bytes of heap per payload byte) is not bounded by the byte limits. With MemoryCacheStore, a few concurrent such responses, each below maxEntrySize and together below maxSize, can exhaust the heap and terminate the process while the advertised byte limits are still satisfied. With SqliteCacheStore, whose maxEntrySize defaults to 2 GB, a single such response is enough. The application only needs to compose the documented cache interceptor with either store and issue cacheable requests to the untrusted origin, which controls only the response. Availability is the only impact.
Patches
Upgrade to 7.30.4 or 8.14.1, which coalesce small body chunks into bounded buffers in both stores so that memory scales with the payload size rather than the chunk count.
Workarounds
Until upgrading, avoid composing the cache interceptor, with either built-in store, with requests to untrusted origins.