Cache helps websites respond faster and reduces server load by storing copies of responses for reuse. However, misconfigured caching can open security vulnerabilities. One such vulnerability is web cache poisoning, a condition where attackers cause the cache to store unintended responses that are then served to other visitors.
This attack doesn’t always require server access. In certain scenarios, attackers exploit differences in how applications and caching systems interpret HTTP requests. Understanding cache keys, headers, and storage rules is essential for prevention.
What is web cache poisoning?
Web cache poisoning occurs when attackers influence responses stored by shared caches—such as reverse proxy caches, CDNs, or web acceleration layers—causing the cache to serve manipulated responses to subsequent requests. The impact depends on the successfully poisoned response: ranging from incorrect content and malicious links to unwanted redirects, and potentially script execution in browsers if the context and other vulnerabilities support it.
Caches aren’t automatically vulnerable simply because they’re active. Risk typically emerges when caches store responses based on partial request attributes, while applications use other attributes to generate content. This discrepancy means two requests considered equivalent by the cache can actually produce different responses from the application.
How can attacks occur?
Imagine a page that builds links based on a specific request header, but that header isn’t included in the cache key. An attacker sends a request with a crafted value. The application generates a response affected by that value, and the cache stores it under a key also used by regular visitors. When other visitors access the same URL, the cache may serve the contaminated response.
Query parameters, unusual headers, host variations, and URL normalization differences can become sources of mismatch. However, not every header or parameter can be exploited. Attackers still need a combination of application behavior and cache rules that allow malicious responses to be stored and reused.
Impact on websites and users
- Manipulated content: visitors see information or links that don’t originate from the site’s intended content.
- Unwanted redirects: cached responses can redirect users elsewhere if applications and caches handle redirects insecurely.
- Service disruption: incorrect pages may continue being served until the cache entry expires or is purged.
- Extended security risks: under certain conditions, poisoned responses can facilitate other attacks, such as malicious scripts executed on the website’s origin.
The severity of impact depends on the affected page, cache duration, shared cache scope, and whether responses require authentication or contain user-specific data.
Practical prevention steps
1. Design cache keys correctly
Review attributes that genuinely affect responses, then ensure they’re included in the cache key or prevented from influencing shared cached responses. Don’t blindly add all headers, as this can reduce cache hit ratios. The goal is aligning cache assumptions with application behavior.
2. Don’t cache personalized responses indiscriminately
Pages loading account information, tokens, personal data, or user-specific content need strict caching rules. Use policies like Cache-Control: private or no-store as appropriate, and don’t rely on shared caches to differentiate users if the mechanism wasn’t designed for that purpose.
3. Validate headers and parameters
Applications shouldn’t build URLs, HTML, or redirects directly from request values without validation. Use allowlists where possible, establish canonical hosts, and reject nonsensical values. Output encoding is also important: input validation doesn’t replace contextual encoding when inserting data into HTML.
4. Test cache behavior before releasing changes
In testing environments, compare responses for different requests to the same URL. Check headers like Age, Vary, Cache-Control, and HIT/MISS indicators provided by CDNs. Ensure variations that change response content don’t incorrectly share cache entries. Conduct controlled testing and avoid testing malicious payloads on production systems without authorization.
5. Prepare recovery and monitoring
Document how to purge specific cache entries, disable problematic cache rules, and restore previous configurations. Monitor for unexpected response spikes, changing redirects, and cache HIT patterns that don’t match expectations. After incidents, review application and CDN configurations—clearing caches alone doesn’t eliminate root causes.
Relationship with CDN and web security
CDNs can accelerate websites while adding rule layers that need review. Use the simplest possible cache rules, limit caching to paths that are genuinely safe, and ensure origin changes don’t make cache assumptions obsolete. For layered protection, also review signature validation policies for webhooks if your website processes requests from external services, and the Core Web Vitals guide for understanding performance optimization without neglecting security.
Conclusion
Web cache poisoning exploits mismatches between how applications generate responses and how caches store and reuse them. The best prevention starts with proper cache keys, strict rules for personal content, request value validation, and regular testing of response variations.
Cache configuration audit checklist
When reviewing configurations, inventory cacheable paths and flag pages loading account data or personalized responses. For each rule, document the cache key, TTL, headers affecting response variations, and responsible parties. Test from both cold cache and warm cache conditions, as first responses and subsequent requests may show different behaviors.
Also check whether tracking parameters that don’t affect content need normalization, and ensure purge rules can be executed during incidents. Store test results as part of configuration change processes so regressions are easier to identify.
Properly configured caches can still deliver performance benefits without making speed a security vulnerability.

Komentar (0)
Belum ada komentar. Jadilah yang pertama berkomentar.