Caches and storage choices
Where data lives and where copies of it hide: CDN and application caches and the attacks on them (poisoning, deception, stale authorisation), and how to choose between relational, key-value, object, search and columnar storage with isolation, encryption and deletion in mind.
01Caches: what they are and what can go wrong
- Place caches at the client, CDN, reverse proxy and application layers and choose cache keys and TTLs
- Recognise web cache poisoning, web cache deception and stale authorisation caches
- Choose between relational, key-value, object, search and columnar storage for a security workload
- Design tenant isolation, encryption at rest and deletion across every copy of the data
What they probe: whether you know a shared cache can serve one user's data to another, how long a revoked permission stays cached, which store suits which access pattern, and how many copies of sensitive data your design creates. Where candidates slip: caching authenticated responses at a CDN, forgetting the search index when deleting data, claiming encryption at rest stops an application compromise.
A cache keeps a copy of a result so the next request is served faster and cheaper. A shared cache (a CDN or reverse proxy) serves many users from one copy, which is where security problems start: the cache decides which requests are "the same" using a cache key, usually the method, host and path. Anything that changes the response but is not in the key can leak or poison.
| Layer | Example | Shared between users? | Typical risk |
|---|---|---|---|
| Browser | HTTP cache | No (one device, but shared computers exist) | Sensitive pages kept on disk |
| CDN or reverse proxy | Cloudflare, Fastly, NGINX | Yes | Poisoning and deception |
| Application cache | Redis, Memcached | Yes, inside your system | Stale permissions, exposed cache server |
| In-process | LRU map in each server | Per process | Inconsistency between servers |
Cache-Control: no-store never store (account pages, tokens, personal data)
Cache-Control: private, max-age=60 browser may store, shared caches must not
Cache-Control: public, max-age=3600 anyone may store for an hour (static assets)
Vary: Accept-Encoding include this request header in the cache key02Attacks on caches
| Attack | How it works | Defence |
|---|---|---|
| Web cache poisoning | An unkeyed input (for example X-Forwarded-Host) is reflected into the response; the attacker's poisoned version is cached and served to everyone | Do not reflect unkeyed headers; strip them at the edge; include anything that changes output in the key |
| Web cache deception | Victim is lured to /account/settings/x.css; the app ignores the suffix and returns the account page; the CDN caches it as a static file; the attacker fetches it | Cache by explicit route rules and response Cache-Control, not by file extension; return 404 for unknown paths |
| Cached authenticated response | A personalised page is served from a shared cache to another user | no-store or private on personalised responses; never cache responses that set cookies |
| Stale authorisation | Permissions cached for 30 minutes; a fired employee keeps access until expiry | Short TTLs for authz, explicit invalidation on revoke, versioned policy |
| Exposed cache server | Redis or Memcached reachable without authentication | Private network only, authentication and TLS on, no default ports to the internet |
revocation SLO a removed user loses access within 60 s
authz cache TTL 300 s -> worst case 300 s of access after revoke: violates SLO
fix A TTL 60 s: 5x more lookups to the policy service
fix B TTL 300 s + revoke event that deletes the user's entries
(TTL is the backstop if the event is lost)If two requests share a cache key, the cache treats them as identical. Before caching anything, ask: could two different users, tenants or permission levels produce the same key? If yes, either add the distinguishing value to the key or do not cache it in a shared layer.
03Choosing storage
| Store | Good at | Security notes |
|---|---|---|
| Relational (PostgreSQL, MySQL) | Transactions, constraints, joins; users, permissions, cases | Row-level security, parameterised queries, least-privilege DB users |
| Key-value (DynamoDB, Redis) | Very fast lookups by key at scale; sessions, counters, tokens | Access is by key, so design keys so a tenant cannot guess another's |
| Object storage (S3, GCS) | Cheap, durable blobs; uploads, logs, backups | Block public access, presigned URLs, Object Lock for write-once retention |
| Search index (OpenSearch, Elasticsearch) | Full-text and faceted search; log search, case search | A full extra copy of the data, often forgotten in deletion and access reviews |
| Columnar files or warehouse (Parquet, BigQuery) | Large scans and aggregates; a year of security logs | Broad analyst access; column-level controls and masking |
Tenant isolation
| Model | Isolation | Cost |
|---|---|---|
Shared tables, tenant_id column | Weakest: one missing filter leaks data; enforce with row-level security | Cheapest, simplest to operate |
| Schema or database per tenant | Stronger: queries cannot cross by accident | More objects to migrate and monitor |
| Account or cluster per tenant | Strongest blast-radius control, per-tenant keys | Most expensive; for large or regulated tenants |
Disk and backup encryption protects against stolen drives, discarded hardware and some misconfigured snapshots. It does nothing against an attacker who controls the application or its database credentials, because the database decrypts for them. Application-level encryption with per-tenant keys is the step that limits that.
04Copies, deletion and failure
- List every copy: primary, replicas, caches, search index, warehouse, backups, logs, the stream. Each needs access control and a deletion story.
- Backups are usually immutable for weeks; deletion requests need crypto-shredding or a documented expiry window.
- When the cache is down, the system must still work (slower). A cache that is also the only copy is a database without the guarantees.
- A cache stampede (thousands of requests miss at once after expiry) can take out the backend; use request coalescing and jittered TTLs.
| Choice | Gain | Cost |
|---|---|---|
| Cache authz decisions | Fast hot path | Revocation lag unless invalidated |
| Search index of logs | Analysts find things in seconds | Another copy to secure and delete |
| Shared tables with row-level security | Cheap multi-tenancy | Isolation rests on a policy being correct everywhere |
05Summary, follow-ups and self-test
"Static assets go through the CDN with long TTLs, but anything personalised is no-store, and the CDN caches by explicit route rules rather than file extension, which closes off cache deception. Permission checks are cached for five minutes with a revoke event that clears them, so a removed user loses access in seconds and the TTL is only a backstop. Cases live in PostgreSQL with row-level security on tenant ID, logs go to object storage as Parquet, and I'd note that the search index is a full extra copy we have to include in access reviews and deletion."
Q1How would you test for web cache deception?+
Request a personalised URL with a static-looking suffix while logged in, then fetch the same URL without credentials from another client and see if the CDN serves the private content.
Q2When would you choose a database per tenant?+
When tenants are large, regulated or contractually promised isolation, or need their own keys and residency. The cost is operational: many databases to migrate and monitor.
Q3Is Redis safe as a session store?+
Yes, with authentication, TLS, a private network and nothing persisted beyond what is needed. Treat it as holding bearer credentials: anyone who can read it can become any logged-in user.
A CDN caches anything ending in `.css`. The app routes `/account/profile/anything` to the profile page. A victim visits `/account/profile/x.css` from an attacker's link. What happens?