Next.js API behind Vercel Edge intermittently returns 403 due to cached edge responses dropping Cookie headers
Environment
Next.js 13.4 app using App Router and edge functions deployed to Vercel Edge. Sessions are cookie-based (HttpOnly session cookie). App serves both SSR pages and API routes; caching rules include a CDN-level cache with default TTL and some routes use revalidate headers.
Symptoms
Some authenticated users intermittently receive 403s from API routes that validate the session cookie. Affected requests are random across users and appear only when requests are served from Vercel's Edge (regional cache). Switching the function to a Node serverless regionally-hosted function eliminates the 403s. Clearing the browser cache or waiting a few minutes sometimes resolves the problem for a user.
Observations
Vercel edge logs show requests served from edge cache without a Cookie header forwarded to the origin in several 403 cases. When a 403 occurs, timestamped logs from the origin show no Cookie present. Requests that hit origin directly (cache-miss) show a Cookie header. The app uses Cache-Control: s-maxage=60 on some pages and differing cache profiles for API and SSR routes. No app code is actively removing cookies before forwarding.
Already attempted
Disabled edge caching for the API routes (set cache-control: no-store) — problem disappeared for those routes. Attempted to set Vary: Cookie header and changed Cache-Control to private on SSR pages, but intermittent 403s still observed on mixed routes. Added custom cache keys in Vercel config for some endpoints (no consistent fix). Rewrote auth to use Authorization bearer tokens — immediate fix but required client-side changes.
Question
How should Next.js and Vercel be configured so edge caching does not cause cookie-stripping or stale cached responses for routes that require cookie-based authentication? What configuration is safest and lowest-effort to ensure edge nodes forward Cookie headers (or avoid caching) without exposing private data to the CDN?
Verified community troubleshooting
No answers yet..