FULL AI ANALYSIS

Next.js API routes return 401 when Authorization header is stripped behind Cloudflare Access

Generated Oct 18, 2026, 9:45:27 AM

Analysis summary

Requests that arrive at the origin without Authorization commonly indicate an edge component (Cloudflare Access, Transform Rules, Workers, or HTTP/2 origin request policy) removing or not forwarding that header. Cloudflare Access may present a JWT to origin instead of forwarding the original header; Cloudflare Workers or Transform Rules can explicitly delete or rewrite headers. Also some origin-request settings used by Cloudflare (or the hosting platform) may normalise or omit sensitive headers when using HTTP/2 or when credentials are not allowed to be forwarded to third-party origins.

Possible causes

Cloudflare Worker or Transform Rule unintentionally deleting Authorization header

85%

Cloudflare Access configured to exchange user token and not forward client Authorization to origin

65%

Origin request policy / HTTP/2 header conversion dropping sensitive headers between edge and origin

40%

Intermittent client behavior sending Authorization only in certain connections (unlikely since direct origin shows header)

10%

Suggested fixes

1

Diagnostic step 1

Re-enable Cloudflare Worker but instrument it to log incoming headers (mask tokens) and explicitly forward Authorization to origin (add request.headers.set('authorization', incomingAuth)) for the API pathname.

2

Diagnostic step 2

Check Cloudflare Transform Rules and Page Rules for any header removal; disable or adjust rules affecting /api/*.

3

Diagnostic step 3

In Cloudflare Access application settings, enable 'JWT assertion' forwarding or configure 'Forward original Authorization' to origin if available; alternatively accept Cloudflare's assertion header and update origin to use it.

4

Diagnostic step 4

Verify Origin Request Policy / HTTP/2 settings on Cloudflare and Vercel: ensure 'preserve client headers' or equivalent is enabled for Authorization, and test with curl via Cloudflare edge to origin.

5

Diagnostic step 5

If tests still fail, capture edge request headers from multiple CF edge locations (via Worker) and open Cloudflare support ticket with edge request samples.