undici vulnerable to cache poisoning and cross-host disclosure via a mismatched Host header
Description
Impact
undici's cache interceptor (interceptors.cache()) looks up and stores responses by the request's origin, method and path, but undici sends an explicit Host request header to the server as given. When an application sends requests for several hosts to one origin by setting the Host header, a cacheable response for one Host is stored under the shared origin key and served to a later request for a different Host, without that request reaching the server. This can disclose one host's response to callers of another, and lets a caller who controls the Host header of one request choose the response that other requests to the same origin and path receive.
The cache interceptor was introduced in undici 7.0.0, and all 7.x and 8.x releases before the patched versions are affected. Applications are affected only when they compose interceptors.cache() and send requests whose Host header names a different authority than the request origin. Responses that include Vary: Host are not affected.
Patches
Upgrade to undici 7.30.4 or 8.14.1. Requests whose Host header names a different authority than the origin now bypass the cache entirely. Persistent stores such as SqliteCacheStore populated before upgrading may still hold cross-host entries and should be cleared.
Workarounds
Do not compose interceptors.cache() on dispatchers that send requests with an explicit Host header for a different host, use a separate dispatcher and cache store per host, or have the server send Vary: Host on responses that differ by host.