undici vulnerable to cross-user cache disclosure via mismatched-ETag 304 revalidation
Description
Impact
undici's cache interceptor, when composed with a shared cache (type: 'shared', the default) and serving a response inside its stale-while-revalidate window, revalidates the stored response in the background. When that background 304 Not Modified carries an ETag that differs from the cached representation, undici reuses the stored body and merges the 304's metadata around it, binding the old body to the new validator and freshness policy. The synchronous revalidation path already rejects a mismatched validator and refetches; the background path did not.
A remote origin that answers the background conditional request with a 304 and a different ETag can therefore make the shared cache keep serving a stale representation, re-stamped with the new validator and lifetime, to later callers. On a shared cache that holds per-caller or otherwise sensitive responses, this can disclose one caller's body to another and serve a body the origin has already replaced. Applications are affected only when a shared cache store is used and the origin returns a mismatched-ETag 304 during background revalidation; per-caller stores and genuinely public representations are not affected. The cache interceptor was introduced in undici 7.0.0, and the background revalidation reuse is present from 7.17.0 through the patched versions.
Patches
Upgrade to 7.30.4 or 8.14.1. The background revalidation path now compares the 304 response's ETag with the cached representation's validator before reusing the body, and on a mismatch it discards the stored entry and refetches unconditionally, matching the synchronous path.
Workarounds
Use a per-caller cache store instead of a shared one for responses that are not safe to serve across callers, or set no-store or private on such responses so they are not retained in a shared cache.