List request headers a cached handler reads in varies
nitro/cache/require-varies-for-header-readsrc/rule-packs/nitro/rules/require-varies-for-header-read.ts Upstream docs Run this rule
pnpm vite-doctor . --framework nitro --rules nitro/cache/require-varies-for-header-read
Why it matters
Nitro narrows the request to the headers listed in varies. Nitro 3 also keeps host, keeps authorization when allowAuthorization is true, and filters cookies to the names in a nonempty allowCookies list, even if varies includes cookie. Nitro 3 uses the live request when it bypasses the cache, for example for non-GET/HEAD methods or requests with a Range header. Without a varying input in the cache key, requests for different tenants, languages, or users can share one response.
Recommended fix
Add each header the handler reads to varies to pass it through to the cached handler. Nitro's default cache key varies by these headers. If you supply a custom getKey, include the inputs the response varies on in that key, or remove it to use Nitro's default key. In Nitro 3, use allowCookies to pass through named cookies instead of varying on the whole cookie header.
Useful links
Example
List the header in varies
Before
export default defineCachedEventHandler((event) => {
const tenant = getHeader(event, 'x-tenant')
return loadDashboard(tenant)
}, { maxAge: 60 })
After
export default defineCachedEventHandler((event) => {
const tenant = getHeader(event, 'x-tenant')
return loadDashboard(tenant)
}, { maxAge: 60, varies: ['x-tenant'] })