Our CDN served one customer's dashboard to other customers for eleven minutes
A config change meant to speed up static pages made the CDN cache an authenticated dashboard response, Set-Cookie and all. Visitors received another user's page and session. The headers that caused it, the incident response, and the cache rules we enforce now.
The first report came through live chat at 14:07: "Why am I seeing someone else's company name on my dashboard?" Two more arrived in the next three minutes. One customer sent a screenshot showing another company's shipment list, with names and delivery addresses.
We are a logistics platform and the dashboard at /app/dashboard is server-rendered HTML behind login.
It should never be the same for two people.
The on-call engineer checked the response headers from their own browser:
HTTP/2 200
content-type: text/html; charset=utf-8
cache-control: public, max-age=600
set-cookie: session=eyJ1c2VyIjoiNDQ5MSIs...; Path=/; HttpOnly; Secure; SameSite=Lax
age: 412
x-cache: HIT
x-cache: HIT and age: 412 meant the CDN had served this response from its cache, and it had been
there for nearly seven minutes. The set-cookie in a cached response meant every visitor who got this
copy also received the original user's session cookie, and was therefore logged in as that user on the
next request.
At 14:12 we purged the CDN cache for /app/* and set a rule to bypass cache on that path. Reports stopped
at 14:18, when the last browser that had picked up the bad cookie made its next request.
How the header got there
cache-control: public, max-age=600 was not something the dashboard code sent. A pull request merged
that morning had added a middleware to improve performance of marketing pages:
@app.middleware("http")
async def cache_headers(request, call_next):
response = await call_next(request)
if request.method == "GET" and response.status_code == 200:
response.headers.setdefault("Cache-Control", "public, max-age=600")
return response
The intent was "cache successful GETs unless the page says otherwise". The dashboard view did not set any
Cache-Control header, because it never had to: before this middleware, our framework sent no caching
header, and the CDN's default for responses without one was to not cache HTML. With the middleware, every
page that did not opt out became publicly cacheable for ten minutes.
What each header told the CDN
| Header | Meaning to a shared cache |
|---|---|
Cache-Control: public |
any cache, including shared ones, may store this |
max-age=600 |
the stored copy is fresh for 600 seconds |
no Vary |
the cached copy is valid for every request to this URL, regardless of cookies |
Set-Cookie |
the CDN's documented behaviour was to cache it with the body when the response was marked cacheable |
RFC 9111, the HTTP caching specification, says a shared cache must not store a response with
Cache-Control: private, and no cache may store one with no-store. It does not forbid caching a
response that has Set-Cookie. Many CDNs refuse to cache those by default as a safety measure, but that
is a product choice, and several providers let an explicit public override it. Ours did.
Why the cache key made it worse
A CDN decides whether two requests are "the same" by its cache key, by default the method, host and
path. Our session lives in a cookie, and cookies were not part of the key. So the first logged-in user to
request /app/dashboard after the middleware was deployed populated the cache, and every later request
to the same path, from anyone, matched it.
Vary: Cookie would have told caches to key on the cookie header, but it is a poor fix: every session is
different, so the hit rate is zero, and some CDNs ignore or reject Vary: Cookie entirely. The correct
answer for per-user content is not to let shared caches store it at all.
Impact
| Item | Value |
|---|---|
| Window | 14:01 (first cached copy) to 14:12 (purge), plus cookie tail to 14:18 |
| Affected path | /app/dashboard and 3 other authenticated HTML pages |
| Exposed | one account's dashboard content and session cookie, served to 63 visitors |
| Stack | Python 3.12 / FastAPI behind a commercial CDN |
1. Contain
Right after the purge:
- Revoked every session issued in the window, and the original user's session in particular, which had been shared with 63 browsers.
- Reverted the middleware.
- Notified the affected customer and, after review with our privacy lead, followed our data-incident process for the exposed delivery addresses.
2. Make the safe default explicit
Instead of "cache unless told not to", the rule is now "never cache unless told to". Authenticated responses get an explicit header, and public caching is opt-in per route:
PRIVATE = "private, no-store"
@app.middleware("http")
async def cache_headers(request, call_next):
response = await call_next(request)
if "Cache-Control" in response.headers:
return response # the route decided
if request.state.user is not None or "set-cookie" in response.headers:
response.headers["Cache-Control"] = PRIVATE
else:
response.headers["Cache-Control"] = "no-cache" # revalidate, safe default
return response
def cache_public(max_age: int):
"""Decorator for routes that are identical for every visitor."""
def wrap(handler):
@wraps(handler)
async def inner(*args, **kwargs):
response = await handler(*args, **kwargs)
response.headers["Cache-Control"] = f"public, max-age={max_age}"
return response
return inner
return wrap
Why private, no-store for authenticated pages:
privateforbids shared caches (CDN, corporate proxies) from storing it, while allowing the user's own browser to.no-storealso stops the browser keeping a copy on disk, which matters on shared computers. For our dashboard, the slight cost on back-button navigation was acceptable.
3. Defence in depth at the CDN
We do not rely on the origin alone:
- A CDN rule that bypasses cache for any request carrying our session cookie and for the
/app/*and/api/*paths, whatever the origin headers say. - A rule that never caches responses containing
Set-Cookie, overriding the provider's "respect origin" mode. - The cache key for public pages explicitly excludes cookies, and public pages do not set cookies, so a marketing page can never carry a session.
4. Static assets stay fast
The original goal, speeding up public pages, is still met, just explicitly:
@router.get("/pricing")
@cache_public(max_age=600)
async def pricing():
...
Fingerprinted JS and CSS use public, max-age=31536000, immutable from the asset pipeline, unchanged.
1. Automated header checks in CI. An integration test logs in, requests every authenticated route from the router table, and asserts the caching header:
@pytest.mark.parametrize("path", authenticated_routes())
def test_authenticated_pages_are_private(logged_in_client, path):
r = logged_in_client.get(path)
cc = r.headers.get("cache-control", "")
assert "private" in cc and "no-store" in cc, f"{path} sent {cc!r}"
assert "public" not in cc
The test iterates the real route table, so a new authenticated page is covered without anyone adding it.
2. Check through the CDN, not just the origin. A synthetic check runs every five minutes against
production with two test accounts. It requests the dashboard as account A, then as account B, and fails
if B sees A's marker string or if either response has x-cache: HIT:
curl -s -o /dev/null -D - -b "session=$A" https://app.example.com/app/dashboard | grep -i '^x-cache'
# x-cache: BYPASS
3. Review rule. Any change to caching headers, CDN rules or cache keys needs a reviewer from the platform team, and the pull request template asks: "Can this response differ between users? If yes, it must be private."
4. Security implications. This was a data exposure and a session hijack in one. Sessions now bind to more than the cookie (a server-side session record with a rotating token), so a leaked cookie used from a very different client fingerprint triggers re-authentication. That would not have stopped this incident entirely, but it narrows what a leaked session cookie can do.
Takeaways
- Never make "cache by default" the rule. Make shared caching opt-in per route.
- Authenticated or per-user responses:
Cache-Control: private, no-store. - A cached
Set-Cookiehands one user's session to everyone. Configure the CDN to never cache it. - Test caching headers through the CDN with two different accounts, not just against the origin.
References: RFC 9111, HTTP Caching, MDN Cache-Control, MDN Vary, OWASP Session Management Cheat Sheet.
Add a label
Embed this post
<iframe src="https://hibug.me/cdn-cached-private-page-cache-control" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I build and maintain public and partner APIs, currently for a logistics platform with web, mobile and third-party clients all calling the same endpoints. Before that I worked on identity: login, sessions, OAuth integrations and the long tail of edge cases they create. The bugs I care about sit at the contract between client and server. A PUT that wiped fields the client never sent, a cache that served one user's page to another, a field removal that broke app versions still in the wild, a refresh flow that logged people out when two tabs raced. None of these show up in a happy-path demo. My posts walk through how each one surfaced, what the HTTP or auth spec actually says, the fix we shipped and the tests we added so the next change to the API does not repeat it.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.