Skip to content
Cache bugs Write-up Intermediate

DOS via cache poisoning

The author found that certain HTTP headers not included in the cache key (unkeyed) could be used to trigger an error response that was then cached, making the main page of a large company inaccessible. By sending a request with a crafted header, the attacker could poison the cache and cause a denial of service for other users.

Allam Rachid Follow

Published on medium.com

{{media:0}}

Allam Rachid (zhero_), on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This write-up is about web cache poisoning used to cause a denial of service. The researcher, Allam Rachid (zhero_), describes finding two cache poisoning issues that led to a DOS, one of them on the home page of a very large company. The report does not name the company or the program, and it gives no bounty or severity figures.

The feature at the centre of it is the server-side cache: an intermediate memory system that stores the response to certain requests for a limited period and serves that stored response to users who make a similar request, so the web server is less busy. The report contrasts this with client-side (browser) caching, which stores data on the user's machine.

The question the researcher starts from is simple: if a malicious version of the site is cached and then served to users who visit after the attacker, what happens? The answer depends on what the attacker can get stored. A successful poisoning can lead to HTML injection, XSS, open redirection or DOS, depending on the nature of the payload stored in the cache.

Setup

No accounts, roles, tools or versions are described. The work is done from a browser, with a second browser used to check whether the poisoned response is served to someone else. The researcher also mentions that it may be useful to test via another IP address from the same location to confirm the poisoning is effective.

The precondition for the whole technique is a server-side cache in front of the application, and a request component that is not part of the cache key but is reflected into the response in a dangerous way.

Finding it

Reading the cache behaviour

The first step is to analyse the server response. The researcher points to three headers.

  1. X-Cache: a value of HIT means the response comes from the cache; MISS means it does not. The presence of X-Cache is not systematic, and similar headers can perform the same function, with values of HIT or MISS.
  2. Age: the number of seconds since the response or resource was stored in the cache. It is sometimes accompanied by Cache-Control, which holds the caching directives; the important one here is max-age, the time limit in seconds for storing the resource. Together these tell an attacker when to send the malicious request so that it is cached.
  3. Vary: often used to specify additional headers that form part of the cache key. In the response the researcher analysed, these were Accept-Encoding and x-wf-forwarded-proto, but Vary can also include user-agent or cookies. There are sometimes additional headers in the cache key that are not listed in Vary.

From this analysis the researcher knows a cache is in place and that two headers are part of the key: Accept-Encoding and x-wf-forwarded-proto.

Looking for unkeyed headers

The researcher then runs small tests to find interesting headers that are unkeyed, that is, not part of the cache key: X-Forwarded-For, X-Host, X-Forwarded-Scheme and similar. Nothing conclusive came back. Cache deception was also tried at this stage without a conclusive result; the report says the search methods for that will not be detailed here.

What did stand out is the X-Timer header present in the response, which the researcher knows is often reflected if a value is specified in the request. On its own this is harmless for a classic HTML injection or XSS attack, because it is reflected in the headers and not in the HTML code. So the idea was to cause an error in the back end and hope the error response gets saved in the cache.

Exploitation

Step 1: poison the cache through X-Timer

The researcher tried to cause a back-end error hoping the error would be saved in the cache, and the report shows the HTTP request and response as an image. The report shows this exchange as an image rather than as text, so the exact request line, header values and response body are not reproduced here.

A cache buster is added to the URL for the test, in this case ?mycachebuster=zhero_, so that the potentially poisoned version is only reachable through the URL containing that unique parameter and other users are not affected.

Step 2: check from a second browser

A second browser is opened and pointed at the URL containing the cache buster. The report shows the browser view as an image. The result is that the main page is completely inaccessible: the DOS is done.

Step 3: the second DOS through X-Forwarded-Host

In a second case, the unkeyed header that helped was X-Forwarded-Host. Any value sent in this header caused a 404 error that was stored in the cache, making the main page of a large company completely inaccessible. The report again shows the HTTP request and response as an image, and the check from another browser as a second image, with the conclusion "DOS success".

Practical notes from the researcher

  • For the attack to be interesting, the DOS should ideally hit the main home page. A link to a resource such as a CSS or font file does not have much impact.
  • It is sometimes necessary to resend the poisoned request several times before it is stored in the cache. In the response shown above, no cache information appears, so trial and error is needed to understand how the cache behaves.
  • Testing from another IP address in the same location can help confirm the poisoning is effective.
  • It is often necessary to adjust the request headers so they match the target's cache keys, most often User-Agent, Accept-Encoding or Accept-Language. Otherwise the poisoned response cannot be retrieved from the cache in another browser, and X-Cache or a similar header will always return MISS.
  • The same attack is possible without the cache buster. Caching is limited in time, longer or shorter depending on configuration, but an attacker can make the attack effectively permanent with a small script that resends the poisoned requests at regular intervals based on the caching duration.

Root cause

The mechanism is that a request component outside the cache key (an unkeyed header) influences the response in a way that produces an error page, and that error page is then stored and served to other users who send a request with the same key. Because the header is not part of the key, the cache considers the attacker's request and a normal user's request to be the same and hands the stored error to the normal user. The same mechanism underlies the X-Timer case, where the reflected header was used to provoke a back-end error that got cached.

The researcher had identified Accept-Encoding and x-wf-forwarded-proto as key components, and headers such as X-Forwarded-Host and X-Timer were not among them.

Impact

The impact demonstrated is denial of service on the main page of a large company: the page becomes completely inaccessible to users, who are described as likely customers of that company one way or another. The effect lasts as long as the poisoned response stays in the cache, which depends on the caching configuration, and can be extended indefinitely by resending the poisoned request at intervals matched to the cache duration. The report does not give a duration, a number of affected users or any other measurement.

Fix

Variants to test

  1. Reflected timing or tracing headers. Send a value in a header such as X-Timer and look for it echoed in the response headers. A positive result is the value appearing in the response headers, which the researcher used as a lever to try to provoke and cache an error.
  2. Host-override headers. Try X-Forwarded-Host, X-Host and X-Forwarded-Scheme with an arbitrary value. A positive result is an error response, such as a 404, that is then served from the cache to a second browser requesting the same URL.
  3. Cache buster discipline. Always add a unique query parameter during testing, for example ?mycachebuster=zhero_, and confirm the poisoned response is only reachable through that URL. A positive result is the poisoned response being reachable only through the buster URL.
  4. Key matching. Adjust User-Agent, Accept-Encoding and Accept-Language to match the target's key, then check from another browser. If the headers do not match, X-Cache or a similar header will always return MISS.
  5. Illegal header on Akamai. The researcher cites an article by researcher bombon on HackerOne stating that a 400 error can be caused on the Akamai CDN by adding an illegal header:

Whether the error is cached then depends on the cache configuration.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher called Allam Rachid (zhero_) found a way to make the home page of a very large company completely unreachable for ordinary visitors. He did not break into a server, steal data or guess a password. He used a feature that almost every big website relies on to stay fast, called a cache, and turned it against the site.

Here is the everyday version. Imagine a busy coffee shop where the barista keeps a few cups of the most popular drink already poured behind the counter. When someone orders that drink, the barista hands over a ready-made cup instead of making a fresh one. That is much faster and keeps the queue moving. A web cache works the same way: it keeps a copy of a page that many people ask for, and hands out the copy instead of asking the real server to build the page again every time.

Now imagine someone swaps the ready-made cup for a cup of salt water and nobody notices. Every customer who orders that drink gets salt water until the cup is replaced. That is cache poisoning: an attacker gets a bad version of a page stored in the cache, and the cache then serves that bad version to everyone else.

In this case the bad version was not a fake login page or a script. It was an error page. The attacker made the server produce an error, the cache saved the error, and from then on every visitor asking for the home page received the error instead of the site. The site was effectively down. That is a denial of service, or DOS: the service is not stolen, it is simply made unavailable.

The researcher found two separate cases of this within fairly short time intervals. One of them was the home page of a very large company. The report does not name the company or the bug bounty programme, and it gives no bounty amount or severity score.

Allam Rachid (zhero_)
Allam Rachid (zhero_) From the original on medium.com

The idea behind it

The researcher starts from a simple question. If a malicious version of a site gets saved in the cache, and that version is then shown to people who visit after the attacker, what happens?

The answer depends on what the attacker manages to get stored. A poisoned cache entry can carry different kinds of bad content, and the effect changes with it: injected HTML, a cross-site scripting payload, a redirect to another site, or, as here, a denial of service. The report lists these possibilities without going into the others in detail.

What a cache is

A cache is an intermediate memory system. It temporarily stores data so that pages render faster when you browse a website. The report describes two kinds:

  • Client-side (local) caching: this is your browser keeping files on your own machine, so a page you visited before loads faster the next time.
  • Server-side caching: the website's own infrastructure stores the response to certain requests for a limited period, longer or shorter depending on configuration. When a user makes a similar request, the stored response is served directly from the cache instead of being built again by the web server. This takes load off the server, which is why big sites depend on it.

The kind that matters for this attack is the server-side one. Two properties of it set up the problem: the cache gives an identical response to users who made a similar request, and cached responses are kept only for a limited time.

Cache poisoning, defined

The report quotes PortSwigger's definition: web cache poisoning is an advanced technique whereby an attacker exploits the behaviour of a web server and cache so that a harmful HTTP response is served to other users.

In plain words: the attacker finds a way to slip something harmful into the cache, and the cache does the delivery for them, to everybody.

How the cache decides two requests are "similar"

This is the heart of the technique, so it is worth slowing down.

When a request arrives, the cache does not compare the whole request with what it has stored. It compares only certain parts of it. Those parts are called cache keys. The report likens them to a fingerprint: if the fingerprint of the incoming request matches the fingerprint of a stored response, the cache returns that stored response. If there is no match, the cache assumes it has nothing suitable and forwards the request to the web server, which builds a fresh response.

Any part of the request that is not among the cache keys is called unkeyed. The cache ignores it completely when comparing. That is the opening for an attacker. If an unkeyed part of the request, say some header, ends up reflected in the response in a dangerous way, then two things become possible:

  1. Store a poisoned response in the cache.
  2. Have that response served to other users, because the cache never looked at the header the attacker added when deciding whether the requests matched.

Which parts are keys varies from site to site and depends on the cache configuration. Sometimes only the request line and the host are keys and everything else is unkeyed. So an attacker has to spend time analysing the target's cache: which parts are keys, how long entries last, and so on.

From cache poisoning to DOS

The researcher had exploited cache-related issues on several programmes before, and recently found two cache poisoning bugs leading to a DOS within a short interval of each other. One was on a very big company.

The first move is always to look at the server's response. The report highlights three headers.

  1. X-Cache: if its value is HIT, the response came from the cache. If it is MISS, it did not. The report notes that X-Cache is not always present; other headers sometimes do the same job and are easy to recognise because their value is HIT or MISS.
  2. Age: the number of seconds since the response or resource was stored in the cache. It is sometimes accompanied by Cache-Control, which carries the caching directives. The directive that matters here is max-age, the time limit in seconds for which the resource is stored. Together, Age and max-age tell an attacker exactly when to send the malicious request so that it lands in the cache.
  3. Vary: often used to list extra headers that form part of the cache key. In the response the researcher analysed, Vary named Accept-Encoding and x-wf-forwarded-proto. Vary can also include user-agent or cookies. The report warns that some headers can be part of the cache key without being listed in Vary at all.

Cache busters: testing without breaking the site

Before going further, the researcher introduces a concept whose purpose is to stop people from breaking live sites by accident.

Some parts of a request are always part of the cache key, starting with the URL (with some specific exceptions). The report gives this example:

  • If the cache stores the response from https://www.example.com/
  • And a user requests https://www.example.com/?test=test

then the cache compares the keys, finds no identical stored version, and forwards the request to the server. The URL, or request line, is part of the key, so a different URL is a different fingerprint.

Researchers use exactly this behaviour to test safely. During testing they always add a parameter to the target URL, so that the potentially poisoned version is only reachable through the URL containing that unique parameter. Ordinary users keep getting the normal page, and the researcher can experiment quietly. Doing the attack through a cache buster is also required for a proof of concept in the report.

Back to the attack

After reading the response, the researcher knew two things: a cache was in place, and two headers were part of the key, Accept-Encoding and x-wf-forwarded-proto.

The next step was a series of small tests to find interesting headers that were unkeyed, meaning not part of the key. The candidates tried were X-Forwarded-For, X-Host, X-Forwarded-Scheme and similar. Nothing conclusive came back.

The researcher also tried for a cache deception vulnerability at this stage, without a conclusive result. The report says the search methods for that will not be described here, perhaps in a future article.

What did stand out was the X-Timer header, which was present in the response. The researcher knew from experience that this header is often reflected if a value is specified in the request. On its own, that reflection is harmless for a classic HTML injection or XSS attack, because the value appears in the response headers and not in the HTML code of the page. So the plan changed: instead of trying to inject markup, cause an error in the back end and hope the error response gets saved in the cache.

Step 1: poison the cache through X-Timer

The researcher tried to cause a back-end error hoping the error would be saved in the cache, and the report shows the HTTP request and response as an image. The report presents this exchange as an image rather than as text, so the exact request line, header values and response body are not reproduced here.

For the test, a cache buster was added to the URL, in this case ?mycachebuster=zhero_. The reason is the one explained above: the poisoned version should only be reachable through the URL containing that unique parameter, so that other users are not affected while the researcher experiments.

Step 2: check from a second browser

A second browser was opened and pointed at the URL containing the cache buster. The report shows the browser view as an image. The result: the main page was completely inaccessible. The DOS was done.

Step 3: the second DOS through X-Forwarded-Host

In the second case, the unkeyed header that did the job was X-Forwarded-Host. Any value sent in this header caused a 404 error, and that error was stored in the cache. The main page of a large company became completely inaccessible. The report notes that you are surely a customer of that company one way or another. Again the HTTP request and response are shown as an image, and the check from another browser as a second image, ending with the conclusion "DOS success".

Practical notes from the researcher

  • For the attack to be interesting, the DOS should ideally hit the main home page. Knocking out a link to a CSS file or a font file does not have much impact.
  • It is sometimes necessary to resend the poisoned request several times before it is stored in the cache. In the response shown above, no cache information appears at all, so trial and error is the only way to understand how the cache behaves.
  • Testing from another IP address in the same location can help confirm the poisoning is effective.
  • It is often necessary to adjust the request headers so that they match the target's cache keys. Most often the relevant ones are User-Agent, Accept-Encoding or Accept-Language. If they do not match, you will not be able to retrieve the poisoned response from the cache in another browser, and X-Cache or a similar header will always say MISS.
  • The same attack works without the cache buster. Caching is limited in time, longer or shorter depending on configuration, but an attacker can make the attack effectively permanent with a small script that resends the poisoned requests at regular intervals, timed to the caching duration.

Why it works

The mechanism is this: a part of the request that is outside the cache key, an unkeyed header, influences the response in a way that produces an error page, and that error page is then stored and served to other users who send a request with the same key. Because the header is not part of the key, the cache treats the attacker's request and a normal visitor's request as the same thing, and hands the stored error to the normal visitor. The X-Timer case rests on the same mechanism: a reflected header was used to provoke a back-end error that then got cached.

The researcher had identified Accept-Encoding and x-wf-forwarded-proto as key components, and headers such as X-Forwarded-Host and X-Timer were not among them.

Impact

The demonstrated impact is a denial of service on the main page of a large company: the page becomes completely inaccessible to users, who are described as likely customers of that company one way or another. The effect lasts as long as the poisoned response stays in the cache, which depends on the caching configuration, and can be extended indefinitely by resending the poisoned request at intervals matched to the cache duration. The report gives no duration, no number of affected users and no other measurement.

Fix

The report does not say what was changed.

Variants to test

  1. Reflected timing or tracing headers. Send a value in a header such as X-Timer and look for it echoed in the response headers. A positive result is the value appearing in the response headers, which the researcher used as a lever to try to provoke and cache an error.
  2. Host-override headers. Try X-Forwarded-Host, X-Host and X-Forwarded-Scheme with an arbitrary value. A positive result is an error response, such as a 404, that is then served from the cache to a second browser requesting the same URL.
  3. Cache buster discipline. Always add a unique query parameter during testing, for example ?mycachebuster=zhero_, and confirm the poisoned response is only reachable through that URL. A positive result is the poisoned response being reachable only through the buster URL.
  4. Key matching. Adjust User-Agent, Accept-Encoding and Accept-Language to match the target's key, then check from another browser. If the headers do not match, X-Cache or a similar header will always return MISS.
  5. Illegal header on Akamai. The researcher cites an article by researcher bombon on HackerOne stating that a 400 error can be caused on the Akamai CDN by adding an illegal header:

The researcher cites an article by researcher bombon on HackerOne stating that a 400 error can be caused on the Akamai CDN by adding an illegal header. Whether that error is then cached depends on the cache configuration. Whether the error is cached then depends on the cache configuration.

Glossary

  • Cache: an intermediate memory system that temporarily stores data so that pages load faster; here, a store of ready-made responses kept by the website's infrastructure.
  • Client-side caching: caching done on the user's own machine, typically by the browser.
  • Server-side caching: caching done by the website's infrastructure, storing responses for a limited period and serving them to users who make a similar request.
  • Cache poisoning: getting a harmful response stored in a cache so that it is served to other users.
  • Denial of service (DOS): making a service unavailable to its normal users, for example by making a page return an error to everyone.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • Request: what a browser sends to a server, made of a request line (method and URL) and headers.
  • Response: what the server sends back, made of a status line, headers and usually a body.
  • Header: a named field in a request or response carrying extra information, such as what content types the browser accepts.
  • Cache key: the parts of a request that the cache compares to decide whether it already has a matching stored response.
  • Unkeyed: a part of the request that is not in the cache key and is therefore ignored during that comparison.
  • X-Cache: a response header whose value HIT means the response came from the cache and MISS means it did not.
  • Age: a response header giving the number of seconds since the response was stored in the cache.
  • Cache-Control: a response header carrying caching directives.
  • max-age: the Cache-Control directive giving the time limit in seconds for which a resource is stored.
  • Vary: a response header that often lists extra request headers which form part of the cache key.
  • Cache buster: a unique parameter added to a URL during testing so that the poisoned version is only reachable through that URL and other users are unaffected.
  • HTML injection (HTMLi): getting attacker-controlled HTML into a page.
  • XSS (cross-site scripting): getting attacker-controlled script to run in another user's browser.
  • Open redirection: making a site redirect visitors to a destination the attacker chooses.
  • Cache deception: a related class of cache vulnerability that the report mentions but does not detail here.
  • Back end: the server-side application that builds responses; an error there can produce an error page.
  • 404: the HTTP status code meaning the requested resource was not found.
  • 400: the HTTP status code meaning the server considered the request malformed.
  • CDN (content delivery network): a network of servers in front of a site that caches and delivers content; Akamai is one such provider, named in the report.
  • User-Agent: a request header identifying the browser and system making the request.
  • Accept-Encoding: a request header listing the compression formats the browser can accept.
  • Accept-Language: a request header listing the languages the user prefers.
  • X-Forwarded-For: a request header that can carry the client's address through proxies.
  • X-Forwarded-Host: a request header that can carry the original host name through proxies.
  • X-Forwarded-Scheme: a request header that can carry the original protocol (http or https) through proxies.
  • X-Host: a request header that can carry a host name.
  • X-Timer: a request and response header the researcher found reflected when a value is sent in the request.
  • x-wf-forwarded-proto: a header the researcher identified as part of the cache key on the target.
  • IP address: the numeric address identifying a machine on a network; testing from another one can confirm a poisoning is visible to other clients.

More by Allam Rachid

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Web cache poisoning and deception

The lesson behind this report.

A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.