FULL AI ANALYSIS

Cloudflare Worker strips Authorization header when X-Forwarded-For present causing 401s on API POSTs

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

Analysis summary

Evidence points to header normalization or unsafe header merging in the Worker fetch() call when forwarding requests. Cloudflare edge will drop certain sensitive headers unless explicitly forwarded, and adding X-Forwarded-For via Worker can trigger header list merging that inadvertently removes Authorization. Other possibilities include Cloudflare's origin header rules, transform-streams in Worker code, or downstream origin rejecting requests with unexpected proxy headers.

Possible causes

Worker fetch() omitted 'Authorization' in forwarded headers or used Request.clone() incorrectly, causing header to be dropped

85%

Cloudflare edge security or origin rules block Authorization when unexpected X-Forwarded-For value present (e.g., header length/format triggers WAF)

40%

Origin server rejects requests with multiple or malformed X-Forwarded-For headers and treats as unauthenticated

30%

A downstream proxy between Cloudflare and origin strips sensitive headers for specific client IP ranges

20%

Suggested fixes

1

Diagnostic step 1

Inspect Worker code: ensure fetch(request, { headers }) explicitly sets Authorization from original request (use request.headers.get('authorization')) before calling fetch.

2

Diagnostic step 2

Use Request constructor to preserve body and method: new Request(originUrl, { method: req.method, headers: forwardedHeaders, body: req.body }).

3

Diagnostic step 3

Enable debug logs in Workers (console.log) to assert header values before and after modifications but avoid logging secrets; log boolean presence only.

4

Diagnostic step 4

Temporarily set a page rule to bypass Worker and Cloudflare for a test path to confirm origin behavior without Cloudflare.

5

Diagnostic step 5

Check Cloudflare WAF and Transform Rules for rules that inspect X-Forwarded-For or Authorization and temporarily disable them for test path.