Operations 10 min read

Case Study: CORS Failure Caused by CDN Misconfiguration and Its Resolution

This article recounts a real‑world incident where a change to the Access‑Control‑Allow‑Origin header triggered CORS errors for credentialed requests, analyzes the CDN caching and Vary‑header issues that caused inconsistent responses, and outlines the steps taken to fix and prevent the problem.

Ctrip Technology
Ctrip Technology
Ctrip Technology
Case Study: CORS Failure Caused by CDN Misconfiguration and Its Resolution

The author, a senior R&D manager at Ctrip, describes a situation where updating the Access-Control-Allow-Origin header to a specific origin caused client‑side CORS failures when the fetch API was used with credentials: 'include'.

Initially, the static resource service returned the same headers for all requests, including a wildcard * for Access-Control-Allow-Origin. After adding the credentials flag, browsers blocked the request because a wildcard origin is incompatible with credentialed requests.

Investigation revealed that the problem was not in the origin server code but in the CDN layer. Three CDN providers (B, W, and A) serve the resource; B behaved correctly, while W returned mismatched Access-Control-Allow-Origin and omitted the Vary header.

Because the Vary: Origin, Accept-Encoding header was missing, the CDN could not differentiate cached responses for different origins, leading to the wrong Access-Control-Allow-Origin being served to some clients.

The root cause was a CDN bug: when a 304 Not Modified response was returned, the CDN reused a cached response that still contained the wildcard origin, ignoring the correct header from the origin server.

To resolve the incident, the team shifted all traffic to the reliable B provider, worked with the W provider to fix the caching logic, and added a whitelist of resource domains for manual configuration.

Key lessons include the importance of comprehensive testing across all CDN providers after each release, strict adherence to HTTP standards, ensuring resource URLs are unique (e.g., using MD5 hashes), and maintaining clear communication with CDN vendors to handle caching anomalies.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingCacheCDNHTTPWeb DevelopmentCORS
Ctrip Technology
Written by

Ctrip Technology

Official Ctrip Technology account, sharing and discussing growth.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.