Shared Cache Security: Prevent Private Responses from Leaking Across Users

HTTP caches improve performance by reusing responses, but a shared cache becomes a security boundary when it can serve one user's response to another. Reverse proxies, CDNs, service workers, browser caches, and application caches all behave differently. A correct Cache-Control header is essential, yet it cannot fix every custom cache or a cache key that ignores user, tenant, or authorization context.

The safest starting question is: could this response contain user-specific data, credentials, account state, or permissions? If yes, determine which components might store or reuse it, then give each layer explicit cache rules. Do not assume that a URL is public simply because it looks like a static path, and do not rely on logout alone to erase cached pages from every browser or intermediary.

Know which cache receives the response

An ordinary browser cache is private to a user profile, while a CDN or reverse proxy is shared among many users. A service worker can add a separate programmable cache that does not follow every HTTP cache expectation. Application-level memoization may share data across tenants if its key omits identity. List every cache in the request path and identify its key fields, storage lifetime, revalidation behavior, and purge mechanism.

RFC 9111 defines important rules for shared caches. For example, a shared cache generally must not store a response to a request containing Authorization unless the response explicitly permits shared storage under the protocol's conditions. The private response directive prevents shared caches from storing the response, while no-store instructs compliant caches not to store it. Neither directive should be treated as a magical control for custom code, browser history, screenshots, or every service-worker implementation.

Set policy at the response that contains the data

For account pages, tokens, personal records, administrative screens, and sensitive API results, use an explicit restrictive policy such as Cache-Control: no-store when storage is inappropriate. Where a browser may keep a private copy but shared storage is forbidden, private can be part of the policy; assess whether the sensitivity warrants no-store. no-cache has a different meaning: a stored response must be revalidated before reuse. It does not mean “do not store.”

For truly public resources, set an intentional freshness lifetime and version static assets with content hashes. Do not apply long-lived public caching to an authenticated route based only on its file extension. A path such as /account/report.css may still return personalized HTML. Cache decisions should use response semantics and application authorization state, not superficial URL shape.

If a response varies based on request headers such as Accept-Language or content encoding, review Vary behavior and make sure the cache key includes the relevant dimensions. Never vary on sensitive identity data in an ad hoc way and assume that all intermediaries honor it. For per-user responses, bypass shared caching or use a cache architecture whose authorization partitioning is explicit, tested, and maintained.

Test the complete path with two users

Use two separate test accounts and sessions in a staging environment. Request the same route as user A, then user B, then user A again. Compare status, body, Age, Cache-Control, Vary, ETag, CDN cache status, and application logs. Clear only the cache under test between experiments so you can identify which layer is serving the response. Repeat with query parameters, trailing slashes, encoded paths, and content-negotiation headers that the application actually supports.

Test both cache deception and cache poisoning hypotheses safely. Cache deception occurs when a dynamic response is mistaken for a static asset and stored; cache poisoning occurs when unkeyed request input influences a response that is later reused. Do not test with another user's real data or public production accounts. Use harmless marker values in a controlled domain and verify results with the site owner before expanding scope.

Inspect logged-out behavior as well. After logout, revisit sensitive pages with browser back navigation, reload, and a fresh request. The application should re-check authorization server-side and sensitive responses should not be available from an unintended shared cache. A visible page remaining in browser memory is different from a server authorization bypass, so test the HTTP response and the user-visible behavior separately.

Review CDN and service-worker rules

CDNs may override origin headers with cache rules. Inventory page rules, cache rules, workers, and bypass conditions. Confirm that authorization cookies, API routes, and account pages are not covered by broad “cache everything” rules. If a CDN caches based on selected cookies, ensure the allowlist cannot omit a permission-bearing cookie after a product change. Test an actual CDN point of presence after changing configuration; a local origin test cannot prove edge behavior.

Service workers should cache only known public assets or explicitly reviewed responses. Avoid caching arbitrary navigation or API responses using a catch-all strategy. Version cache names and include a controlled cleanup plan for old caches. When access rights change, ensure relevant application caches are invalidated or reauthorized before reuse.

Respond to a suspected cross-user cache leak

Disable the unsafe cache rule or bypass caching for the affected route, then purge the relevant cache keys. Preserve request IDs and cache metadata needed for investigation without collecting extra personal data. Determine the first affected version, the range of users and records potentially exposed, and whether the response was publicly indexed or retained by a third party. Follow the organization's incident response and breach-notification obligations; a cache configuration bug can be a data incident even if the origin database remains secure.

Safe-testing and maintenance note

Use only test accounts and systems you own or are authorized to assess. Use fake records and stop immediately if another person's data appears. Recheck CDN and service-worker behavior after major routing or hosting changes. Last updated: 2026-11-09. Change log: Initial publication; caching directives checked against RFC 9111 and OWASP guidance.

References