Practical technical guides / Core IT: networking (HTTP shared caching)

A CDN Served One Customer Account Page to Another: Shared Caches, Cache-Control private, Vary and Set-Cookie

max-age=60 meant for browsers let a shared cache serve one customer account page to two others. RFC 9111 rules, CDN minimum TTLs, Vary and a header test that catches it.

By Sandeep Belgavi · Published 2026-11-09

max-age=60 meant for browsers let a shared cache serve one customer account page to two others. RFC 9111 rules, CDN minimum TTLs, Vary and a header test that catches it.

An account page served to the wrong customer

Belgavi's Book Store put a CDN in front of its website to speed up the catalogue. A week later, Jenya opened /account and saw Geetha's name and recent orders. Nothing was hacked. The account page had been served with Cache-Control: max-age=60, which a developer had added so that browsers would not refetch it on every back-button press. The CDN read the same header, stored Geetha's page for 60 seconds, and served it to the next two customers who asked for /account.

This guide works through the rules in RFC 9111, HTTP Caching, that decide when a shared cache may store and reuse a response, shows where CDN settings override them, and turns that into headers and a test. The companion code implements those rules for a shared cache and replays the store's mistake under nine header and configuration choices. It models the rules; it is not a CDN.

Private caches and shared caches

RFC 9111 distinguishes a private cache, which serves one user (a browser's cache), from a shared cache, which serves many (a CDN, a reverse proxy, a corporate proxy). Most of the rules are the same. The ones that matter for personal pages are the ones that differ.

Section 3 lists the conditions under which any cache may store a response. For a shared cache, three of them are decisive:

  • the no-store directive is not present;
  • the private response directive is not present;
  • the request did not carry an Authorization header, unless the response explicitly allows shared caching with public, s-maxage or must-revalidate (section 3.5).

And the response must carry something that makes it cacheable at all: public, max-age, s-maxage, an Expires header, or a status code that is heuristically cacheable, which includes 200.

So Cache-Control: max-age=60 on a 200 response to a cookie-authenticated request is storable by a shared cache. The rules have no concept of "this page is personal". They only know what the headers say.

Cookies do not make a response private

The store's developers assumed that because the page depended on the session cookie, a cache would not share it. RFC 9111 section 7.3 says the opposite: "the Set-Cookie response header field does not inhibit caching; a cacheable response with a Set-Cookie header field can be (and often is) used to satisfy subsequent requests to caches." The same is true of a Cookie request header. Unless the cache is configured to key on it, or the response says Vary: Cookie, a cookie is just another header.

Some caches are more conservative than the RFC by default. Varnish's built-in VCL passes any request that carries Cookie or Authorization straight to the origin, and treats a response with Set-Cookie or Cache-Control: private as uncacheable. Many teams override exactly those defaults to raise their hit rate, often by stripping cookies in vcl_recv, and then personal pages become cacheable.

The afternoon, replayed

The companion example sends four requests through one shared cache: Geetha, Jenya, Tanishka, then Geetha again, ten seconds apart, each with a separate session cookie. The origin personalises the page from the cookie.

Response headers and cache settingPages shown to the wrong customerCache hits
max-age=602 (Jenya and Tanishka both see Geetha)3
private, max-age=6000
no-store00
max-age=60 with Vary: Cookie01
private, max-age=60, CDN minimum TTL 300 s23
max-age=60, credentials in Authorization00
public, max-age=60, credentials in Authorization23
max-age=60 plus Set-Cookie: cart=...2, and both receive Geetha's cookie3
max-age=60, cookie in the CDN cache key01

Four rows deserve a note.

private is the intended fix. It keeps the browser benefit the developer wanted (a private cache may still store it for 60 seconds) and forbids shared caches from storing it.

A CDN minimum TTL can override the origin. CloudFront's documentation says that when the origin adds no-cache, no-store or private, CloudFront respects them only if the minimum TTL is 0; with a minimum TTL above 0, CloudFront caches the object for the minimum TTL. One setting chosen for static assets, applied to the whole distribution, undoes the header.

Authorization is protected until someone adds public. Section 3.5 stops shared caches from reusing responses to authenticated requests, unless the response opts in. Adding public "to make caching work" for an API opts every user's response in.

Set-Cookie gets cached along with the body. The second and third customers receive Geetha's cart cookie as well as Geetha's account page.

Vary and the cache key

Vary: Cookie tells a cache that the stored response may be reused only for requests whose Cookie header matches. RFC 9111 section 4.1 requires that; Vary: * means it never matches. It prevents the leak, but every customer gets a separate copy, and any change to any cookie (an analytics cookie, a consent cookie) creates another. In the replay, it saved one origin request out of four. For pages that are genuinely personal, private is simpler and says what you mean.

CDNs also let you choose the cache key directly. CloudFront separates the cache policy (what forms the key) from the origin request policy (what is forwarded to the origin). Its documentation describes the origin request policy as the way to send information to the origin without including it in the cache key. That is exactly the configuration in which a page can vary by a cookie the cache does not key on: forward the session cookie for personalisation, leave it out of the key for hit rate, and every customer shares one copy.

Headers that say what you mean

Decide per route, not per site:

# Personal pages and APIs
Cache-Control: private, no-store          # or private, max-age=0 if back-button caching does not matter

# Public catalogue pages
Cache-Control: public, max-age=60, s-maxage=600

# Public pages that set a cookie: do not set cookies on cacheable responses

Then make the CDN agree: minimum TTL 0 on personal paths, cookies and Authorization either excluded from forwarding or included in the cache key, and a separate behaviour for static assets with their own long TTLs.

A test that would have caught it

A unit test on the origin that asserts headers per route is cheap and catches the developer's change:

def test_account_page_is_not_shared_cacheable(client):
    r = client.get("/account", cookies={"session": "test-geetha"})
    cc = {d.strip().split("=")[0] for d in r.headers["Cache-Control"].lower().split(",")}
    assert "private" in cc or "no-store" in cc
    assert "public" not in cc and "s-maxage" not in cc

It does not catch the CDN override. For that, run a two-user test against the real edge in a staging environment: sign in as two test customers, request the same personal URL as both within the TTL, and assert that each one sees only the data of that account and no Age or cache-hit header on the second response.

Failure modes

  • Headers set for browsers, read by CDNs. max-age applies to both kinds of cache. Use private when only browsers should store.
  • Framework defaults that change. A framework upgrade or middleware that adds caching headers to every 200 response can turn personal pages cacheable. The header test above catches it.
  • Error and redirect pages. RFC 9110 lists 301 and 404 among the status codes that are heuristically cacheable, so a personalised one can be stored without any freshness header; a 302 can be stored when it carries explicit freshness such as max-age.
  • Purge is not a fix. Purging after a leak removes the copy, not the cause. Fix headers and configuration first.

When this is unnecessary

If nothing personal is ever served from a cached hostname, for example account pages live on a separate origin that bypasses the CDN entirely, the risk is architectural rather than per header. Even then, keep the header test: routes move.

Verification

The companion tests assert each row of the table above, that Vary: * never matches, and that directive parsing is case-insensitive. They verify the model of the rules, not any CDN. For the edge, use the two-user staging test.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/shared_cache_rules. Views are my own and do not represent any employer, past or present.