Web Cache Deception Vulnerabilities
Web Cache Deception Vulnerabilities
Web Cache Deception Vulnerability and Exploitation
What is it?
A vulnerability that enables attackers to trick web caches and gain unauthorized access to sensitive information. It is caused by inconsistencies between how the cache server and origin server handle requests.
How Does It Occur or Work?
Typical CDN Workflow:
- User opens content on a website.
- Request flows as follows:
- User → CDN (Content Delivery Network) → Origin Server.
- The CDN caches (saves) the response for reuse to reduce load and improve speed.
- Subsequent requests may fetch data from the CDN cache directly.
How Does the Vulnerability Work?
An Example:
- Normal Functionality:
- A logged-in user visits their profile at:
1
https://example.com/profile
- This page is dynamically generated and contains user-specific data (e.g., name, email).
- It is not cached as it is private.
- A logged-in user visits their profile at:
- The Attack:
- An attacker manipulates the URL:
1
https://example.com/profile/public.css
- The server mistakes this for a static file request, allowing the content to be cached.
- An attacker manipulates the URL:
- The Consequence:
- If this dynamic content is cached, others accessing the manipulated URL might see the sensitive profile data.
Web Caches
What are Web Caches?
Web caches temporarily store copies of web pages, images, or other resources to speed up access and reduce server load.
Types of Web Caches:
- Browser Cache: Stores resources locally in a user’s browser.
- Server-Side Cache: Stores content on the web server for frequently accessed pages.
- CDN (Content Delivery Network): Distributed caches near users to deliver content faster.
Cache Keys
- When a cache receives an HTTP request, it determines if a cached response exists based on a cache key.
- Cache keys typically include:
- Base URL:
example.com/page. - Query parameters:
id=123.
- Base URL:
Example:
- Request:
https://example.com/page?id=123. - Cache key:
example.com/page?id=123.
If a match is found, the cached response is served.
Cache Rules
Types of Rules:
- Static File Extension Rules:
- Target file types:
.css,.js,.png.
- Target file types:
- Static Directory Rules:
- Apply to paths starting with
/staticor/assets.
- Apply to paths starting with
- File Name Rules:
- Target specific files like
robots.txtorfavicon.ico.
- Target specific files like
Static vs. Dynamic Files in Websites
Static Files
- Definition: Content that does not change unless updated by a developer.
- Examples:
.html,.css,.js,.jpg,.woff.
Dynamic Files
- Definition: Content generated in real-time, customized for each request.
- Examples:
.php,.jsp,.py.
How to Identify if a File is Static or Dynamic
- File Extension:
- Static:
.html,.css,.js. - Dynamic:
.php,.asp.
- Static:
- URL Behavior:
- Static: Content remains the same for all users.
- Dynamic: Content varies based on user interaction.
- HTTP Response Headers:
- Static:
Cache-Control: public, max-age=31536000. - Dynamic:
Cache-Control: no-store.
- Static:
Common Exploitation Techniques
Exploiting Path Mapping
- Identify static extensions (e.g.,
.js) by sending: GET /my-account/123.js - If
X-Cache: hitappears, the resource is cached.
Exploiting Path Delimiters
- Use delimiters (
;,?) to bypass cache rules: GET /my-account;public.js
Exploiting Origin Normalization
- Use traversal (
../) to target sensitive paths: /resources/..%2fmy-account
Exploitation Labs
Lab: Exploiting Path Mapping
- Identify caching behavior:
- Send requests like
/my-account/123.js. - Observe
X-Cacheheaders (miss, thenhit).
- Send requests like
- Exploit:
- Redirect user to malicious URL:
1 2 3
<script> document.location="https://YOUR-LAB-ID.web-security-academy.net/my-account/123.js"; </script>
- Redirect user to malicious URL:
Lab: Exploiting Path Delimiters
- Test Delimiters:
- Send
/my-account;123.js. - Observe
X-Cache: hit.
- Send
- Exploit:
- Use
<script>to cache sensitive data for victim users.
- Use
Lab Workflow Summary
- Identify Vulnerabilities:
- Look for mismatched cache rules or normalization issues.
- Test Static and Dynamic Paths:
- Check responses for
X-Cache: miss→hit.
- Check responses for
- Craft Payloads:
- Combine delimiters, traversal, and static file rules.
- Deliver Exploit:
- Redirect victim users to malicious URLs.
This post is licensed under CC BY 4.0 by the author.