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.

● EasyFREEBy ·Design problem·11 min read·Beginner → Intermediate
cachingweb cache poisoningweb cache deceptionobject storagemulti-tenancyencryption at rest

01Caches: what they are and what can go wrong

✓What you will learn
  • 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
◎Interview radar

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.

LayerExampleShared between users?Typical risk
BrowserHTTP cacheNo (one device, but shared computers exist)Sensitive pages kept on disk
CDN or reverse proxyCloudflare, Fastly, NGINXYesPoisoning and deception
Application cacheRedis, MemcachedYes, inside your systemStale permissions, exposed cache server
In-processLRU map in each serverPer processInconsistency between servers
Headers that tell caches what they may dotxt
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 key

02Attacks on caches

AttackHow it worksDefence
Web cache poisoningAn unkeyed input (for example X-Forwarded-Host) is reflected into the response; the attacker's poisoned version is cached and served to everyoneDo not reflect unkeyed headers; strip them at the edge; include anything that changes output in the key
Web cache deceptionVictim 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 itCache by explicit route rules and response Cache-Control, not by file extension; return 404 for unknown paths
Cached authenticated responseA personalised page is served from a shared cache to another userno-store or private on personalised responses; never cache responses that set cookies
Stale authorisationPermissions cached for 30 minutes; a fired employee keeps access until expiryShort TTLs for authz, explicit invalidation on revoke, versioned policy
Exposed cache serverRedis or Memcached reachable without authenticationPrivate network only, authentication and TLS on, no default ports to the internet
Sizing an authorisation cache against a revocation SLOtxt
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)
!Cache keys decide who sees what

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

StoreGood atSecurity notes
Relational (PostgreSQL, MySQL)Transactions, constraints, joins; users, permissions, casesRow-level security, parameterised queries, least-privilege DB users
Key-value (DynamoDB, Redis)Very fast lookups by key at scale; sessions, counters, tokensAccess is by key, so design keys so a tenant cannot guess another's
Object storage (S3, GCS)Cheap, durable blobs; uploads, logs, backupsBlock public access, presigned URLs, Object Lock for write-once retention
Search index (OpenSearch, Elasticsearch)Full-text and faceted search; log search, case searchA 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 logsBroad analyst access; column-level controls and masking

Tenant isolation

ModelIsolationCost
Shared tables, tenant_id columnWeakest: one missing filter leaks data; enforce with row-level securityCheapest, simplest to operate
Schema or database per tenantStronger: queries cannot cross by accidentMore objects to migrate and monitor
Account or cluster per tenantStrongest blast-radius control, per-tenant keysMost expensive; for large or regulated tenants
iWhat encryption at rest buys

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.
ChoiceGainCost
Cache authz decisionsFast hot pathRevocation lag unless invalidated
Search index of logsAnalysts find things in secondsAnother copy to secure and delete
Shared tables with row-level securityCheap multi-tenancyIsolation rests on a policy being correct everywhere

05Summary, follow-ups and self-test

▭On the whiteboard · Remember3 points
01
cache
key decides who sees what; no-store on personal data; short authz TTL + revoke events
02
store
pick by access pattern; every extra store is an extra copy
03
isolate
tenant model by blast radius; encryption at rest is not app-level protection
“How to say it in the room

"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.

Test yourself

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?

Finished this one?
Tick it and it shows as done on the roadmap and the course.