Two customers of an online pharmacy write to support on the same afternoon. Each says that after logging in, the account page briefly showed a stranger’s name and order history. Refreshing fixed it. Nobody can reproduce it on demand. This kind of report should set off alarms, because it is both a serious privacy incident and a very specific technical signal. Intermittent cross-user data almost never comes from a wrong database query, which would fail consistently. It comes from something that holds one user’s data and hands it to the next user. Finding that shared something is the whole investigation.

Suspect one: a cache that does not know about users

The most common cause is a cache storing a personalised response and serving it to someone else. There are several layers where this can happen.

CDNs and reverse proxies. A CDN decides what it may cache largely from HTTP headers. If the account page is served without a Cache-Control header saying private or no-store, and someone recently added a CDN rule like “cache everything under this path for 60 seconds”, the first user’s page is cached and served to every visitor for the next minute. This failure is well documented in public: in December 2015, Valve acknowledged that a caching configuration change made during a traffic surge caused some Steam users to see other users’ account pages.

Cache keys missing a dimension. If a response varies by something other than the URL, the cache key must include it. The HTTP Vary header tells caches which request headers matter, but many CDNs handle Vary on cookies or authorisation headers poorly or ignore it, so do not rely on it for personal data. Mark such responses uncacheable at shared layers instead.

Application caches. A developer adds caching to a “get dashboard data” function, keyed by the function name and page number. The user ID is not part of the key. Every user who asks for page 1 now gets the first user’s dashboard until the entry expires.

Suspect two: state stored in the wrong scope

Web frameworks reuse objects across requests, and code that forgets this leaks data between users under concurrency.

Fields on singletons. In Spring, controllers and services are singletons by default: one instance handles every request on every thread. If a developer stores the current user in an instance field “for convenience”, two simultaneous requests overwrite each other’s value. Request A sets the field to Asha, request B sets it to Bilal, and request A then renders Bilal’s orders. Under low traffic it almost never happens, which is exactly why it feels intermittent. The same mistake appears as module-level variables in Python or Node.js servers, which also live for the life of the process.

Thread-locals that are never cleared. Thread-local storage is a reasonable place to keep the current user for one request. But servers run requests on a pool of reused threads. If the filter that sets the value does not clear it in a finally block, and a later request on the same thread skips the code that sets it (for example, an endpoint that is supposed to be anonymous), that request inherits the previous user’s identity.

Asynchronous context mix-ups. Moving work to another thread pool or an async callback can lose the request context, or carry the wrong one, if context propagation is implemented by hand.

Suspect three: pooled connections carrying session settings

Some multi-tenant systems set a per-session variable on the database connection, such as the current tenant ID used by PostgreSQL row-level security policies. Connections are pooled and reused. If the setting is applied at session level and not reset before the connection returns to the pool, the next borrower runs with the previous tenant’s context. Poolers that multiplex at transaction level, such as PgBouncer in transaction mode, add another twist, because consecutive transactions from one client may run on different server connections. Settings should be scoped to the transaction, or reset reliably when the connection is returned.

Investigating without guesswork

A methodical approach narrows the cause quickly:

  1. Get exact times and affected accounts. With a timestamp and both user IDs, you can look for the “donor” request: when did the other user’s data last get legitimately served?
  2. Check response headers and CDN logs. Did the problematic response come from cache? CDNs typically add a header indicating a cache hit. A hit on a personalised page is close to proof.
  3. Correlate with recent changes. New caching rules, a framework upgrade, a refactor that introduced a field on a shared service, or a change to the connection pooler.
  4. Check which server and thread served each request. If the two requests ran on the same instance within milliseconds, shared in-process state is likely. If they ran on different instances, look at shared caches.
  5. Reproduce under concurrency. Singleton and thread-local bugs rarely show up with one tester clicking around. A load test with many distinct users, where each response is checked against the requesting user’s ID, usually surfaces them within minutes.

It is an incident, not just a bug

Because personal data has been disclosed to the wrong people, the response cannot wait for a perfect root cause. Contain first: purge CDN caches, disable the recent caching rule or roll back the release, and if needed force personalised pages to bypass caching entirely. Then involve your security and legal colleagues. In India, the CERT-In directions of April 2022 require certain cyber security incidents, including data breaches, to be reported within six hours of noticing them, and the Digital Personal Data Protection Act, 2023 introduces duties to notify the Data Protection Board and affected individuals of personal data breaches under its rules. Exactly what applies depends on the incident and the current rules, which is why the people who own compliance need to know early.

Designing so it cannot happen

Prevention is mostly about defaults. Make authenticated responses uncacheable at shared layers unless a route is explicitly marked safe. Include the user or tenant ID in every cache key for personal data, ideally through a helper so nobody builds keys by hand. Keep singleton services stateless and pass request data as parameters. Clear thread-local and connection-level state in finally blocks or framework hooks. And add an automated check in tests or monitoring: for a sample of responses, verify that the user ID in the response body matches the authenticated user. That one assertion catches every cause described here.

Written by the RP Strativa Team. The pharmacy scenario and names are illustrative; regulatory obligations should be confirmed with your compliance team.

Leave a Reply

Trending