Nitro · Caching

NITRO0029List request headers a cached handler reads in varies

Reports request headers and cookies read inside a cached event handler when Nitro strips them from the request it passes to that handler. Covers getHeader, getRequestHeader, getCookie, parseCookies, event.headers.get, event.req.headers.get, and event.node.req.headers with a literal name. Nitro 2 handlers are defineCachedEventHandler and cachedEventHandler; Nitro 3 handlers are defineCachedHandler from nitro/cache. Dynamic options, spreads, headersOnly, Nitro 3 shouldBypassCache, and unresolved Nitro 3 cache defaults are evidence gaps and stay quiet.

Why it happens

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.

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.

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'] })

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework nitro --rules nitro/cache/require-varies-for-header-read
Copyright © 2026