Your account page showing for another user? Cache-Control decides

A page with a user's data must not be stored in a shared cache such as a CDN. Per MDN, private keeps it in the browser cache only, no-store stops any cache from storing it, and no-cache does not mean don't cache.

Published 2 min read#App security#Web development#Privacy

A customer opens their account page and sees another customer's name and address. There was no break-in and no database flaw: a cache between the server and the visitors stored the page once, and served it to everyone who asked after that. In this article you will see which header prevents this, and which value in it makes the difference.

What is the Cache-Control header?

The Cache-Control header is an HTTP header that tells caches along the way whether they may store a response, where, and for how long. The server sends it with every response, and the browser and shared caches follow it.

The MDN page on Cache-Control separates two kinds: a shared cache, such as a proxy or a CDN between the server and the visitors, stores a single response and reuses it for many users; a private cache is the browser cache, and it serves one user.

Why does an account page reach someone else?

An account page reaches someone else when it is stored in a shared cache, because that cache returns the same response to everyone who requests the same URL.

The mistake here is human: we set one cache rule for the whole site to make it faster, and forget that /account is one URL for every visitor while its content is different for each of them. MDN says it plainly: if you forget private on a response with personalized content, it can be stored in a shared cache and reused for multiple users, which can leak personal information.

What is the difference between private, no-store and no-cache?

The difference is that private allows storage in the browser only, no-store stops any cache from storing the response, and no-cache allows storage but requires a check with the server before every reuse.

Value

Who stores the response

private

The browser cache only, not a shared cache

no-store

No cache, private or shared

no-cache

Any cache, but it checks with the server before each reuse

The one that confuses people most is no-cache. The page itself says that no-cache does not mean "don't cache", and if what you mean is "don't store", the directive to use is no-store.

How do you protect your pages today?

You protect them by sending private on every page with personalized content, and no-store on pages you don't want saved anywhere.

  1. List the pages that change per user: the account, orders, invoices, the dashboard, and any API that returns their data.

  2. Send Cache-Control: private on those pages at least. MDN recommends it for personalized content, especially responses after login and sessions managed through cookies.

  3. For more sensitive pages, like invoices or payment details, send Cache-Control: no-store so they aren't saved even in the browser.

  4. Open your CDN or hosting settings, check whether there's a cache rule for the whole site, and make sure it follows the header you send.

Cache-Control: no-store

This header works alongside checking your session cookie flags and the Referrer-Policy header: all three keep user data from reaching places it shouldn't.

Where do you start now?

The lesson for us as developers: a cache sees a URL, not a user, so a page that differs from user to user has to say so in the header. Open your account page in the developer tools today, and see what its Cache-Control says.

And if you want someone to review your site's headers and cache settings, there's Muhassan. Which page on your site shows user data, and what header does it send right now?

FAQ

If my site has no CDN, should I care?

Yes. A shared cache can be a proxy between the server and the visitor, or a cache layer in your hosting you never noticed. The header states your decision to any cache on the way.

Will no-store slow my site down?

Only on the pages you put it on, because they are fetched from the server every time. Put it on pages with private data, and let images and public files be cached as usual.

Where do I see the header?

Open the browser's developer tools, go to the Network tab, pick the page request, and look for Cache-Control in the response headers.

Share

More articles