guides · 2026-11-14
Web Cache Poisoning and Deception: Making Your CDN Serve the Attack to Everyone
Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team
The short answer
Caches serve whatever they stored, to everyone, at scale. If a response varies by an input the cache key ignores — X-Forwarded-Host is the classic — an attacker stores a poisoned page once and your own CDN delivers it to all visitors. Cache deception is the mirror: tricking the cache into storing a logged-in page as a public asset. Audit what your cache keys include, mark authenticated responses uncacheable, and never let headers steer generated URLs without validation.
Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.
What is Web cache poisoning?
corrupting a shared cache so a crafted response is stored and served to other users. Cache deception is the sibling: causing a victim's private, authenticated response to be stored under a public-looking URL, where the attacker then retrieves it.
The unkeyed-input principle
A cache key is the list of inputs that distinguish one stored response from another — usually the URL and a few headers. Poisoning exists wherever the application's response depends on something not in the key: the app builds absolute links from X-Forwarded-Host, reflects a header into the page, or localises by a header the cache ignores. The attacker sends the malicious input once; the cache stores the result under the innocent key; every subsequent visitor receives the attacker's page — scripts, phishing forms, defacement — served from your domain at CDN speed. Vibe-Code Audit's cache detector family flags the code shapes: host headers used to build links and redirects, public caching combined with unkeyed inputs, authenticated content marked cacheable, and framework settings like Next.js force-cache on user-parameterised fetches.
Deception: the victim stores their own page
Cache deception inverts the flow. The victim, logged in, is lured to a URL like /account/settings/fake.css — the app ignores the suffix and returns the private settings page; the cache, seeing a .css-looking path, stores it as a public static asset; the attacker requests the same URL and reads the victim's account data from the cache. Defences are boring and total: authenticated responses carry Cache-Control: private, no-store; apps do not serve account pages under asset-like suffixes; caches are configured to respect those headers rather than override them with cheerful TTL rules.
AI-built apps stumble here because caching is added as a performance afterthought — a CDN in front, a cache header copied for speed — with no model of which responses are per-user. The audit question is per-route: can two different users receive different bytes at this URL? If yes, it must never enter a shared cache.
Header hygiene on the application side
Stop deriving URLs from request headers without validation: absolute links, password-reset URLs and redirect targets must come from configured canonical origins, not Host or X-Forwarded-Host — a poisoned reset email is cache poisoning's close cousin, delivered by mail instead. Where a proxy legitimately sets forwarded headers, the application must trust only the proxy's copy (stripped and set at the edge), never the client's. Reflecting arbitrary headers or parameters into responses (JSONP-style callbacks, debug echoes) is the other classic key-gap: if it is in the response, it belongs in the key, or it must not be reflected at all.
Verifying your own cache
Against staging behind the real CDN configuration: request a page with a hostile X-Forwarded-Host and check whether generated links adopt it; request it again without the header and see whether the poisoned version persists (that persistence is the poisoning, demonstrated). Request an authenticated page with an asset suffix and confirm it is neither stored nor served to a second, unauthenticated request. These three probes, plus a review of Cache-Control on every authenticated route, constitute the audit — and belong in the regression suite, because cache rules drift with every performance tweak.
Worked example: VistaTrail, a travel-blog platform with accounts
VistaTrail (fictional), serving about 400,000 page views a month behind a CDN, generated password-reset links from the request's forwarded host header and cached pages aggressively for speed. A scan flagged host-header URL building and public caching with unkeyed input. The staging proof took minutes: a request with X-Forwarded-Host: evil.example produced reset links on the attacker's domain, and the response was cached for the next visitor. Fixes: canonical origin from configuration for all generated URLs, forwarded headers trusted only from the CDN, Cache-Control: private, no-store on every authenticated route, and cache keys reviewed against reflected inputs. The three probes became a post-deploy checklist item.
Five things to do before you ship
- List every place the app builds URLs or redirects from Host or X-Forwarded-Host; replace with a configured canonical origin.
- Inventory routes whose responses differ per user; mark them Cache-Control: private, no-store and confirm the CDN honours it.
- Probe staging: hostile forwarded-host request, repeat without it to check persistence, and an authenticated page under an asset-like suffix.
- Ensure forwarded headers are set only by your proxy/CDN and stripped from client requests at the edge.
- Re-run the probes after any caching or CDN change — performance tweaks are when key discipline silently regresses.
Sources
- OWASP Top 10, the OWASP Foundation's standard awareness list of the most critical web application security risks: owasp.org, 2021
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command, MITRE's weakness entry for SQL injection and its mitigations: cwe.mitre.org, 2026
- OWASP Cheat Sheet Series — Secrets Management, OWASP's best-practice guide to storing, rotating and auditing secrets: cheatsheetseries.owasp.org, 2026
Frequently asked questions
Is this only a risk for huge sites?
Any shared cache qualifies — a CDN plan on a small site is still a shared cache. The attack scales with your traffic, but the poisoning itself works at ten visitors a day.
Does HTTPS prevent cache poisoning?
No. TLS protects data in transit between the user and the cache; poisoning corrupts what the cache legitimately stores and serves over perfectly valid HTTPS.
Why does my app use the Host header at all?
For absolute URLs in emails and redirects, frameworks default to the request's host. The fix is not removing the need but sourcing it from configuration — your canonical origin is a constant, not a request property.
How long does poisoned content live?
Until the cache entry expires or is purged — TTLs of hours to days are common, and every purge-free performance setting extends it. Incident response must include an explicit cache purge for the affected keys.
Related guides
- DOM Clobbering: How a Form Field Named 'config' Silently Replaces Your JavaScript Objects
- Math.random() Is Not a Token Generator: Weak Randomness in Reset Links and Session IDs
- Session Cookies Without HttpOnly, Secure and SameSite: What Each Missing Flag Costs You
- Second-Order Injection: The Payload That Waits in Your Database Until It Reaches a Sink
- What Happens When Your .env File Is Publicly Exposed?
- How an Exposed .git Folder Lets Attackers Download Your Source Code
- 7 Security Mistakes AI Coders Keep Making
- Supply-Chain Attacks in the AI-Coding Era
- Secret Hygiene: Stop API Key Leaks
- What Code Scanners Can't Find
- Scan Your Lovable Code Before Deploying
- LLM Threats in AI-Generated Apps
Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.
Informational explainer, not a security guarantee. Scan your code free before every deploy.