Web Cache Poisoning - Capability to disable/deface the app.██████████.com (A tale of poisoning through the layers of caching)
The application's CloudFront cache ignored query strings and paths in its cache key, and an unkeyed header could be used to poison the cached response. An attacker could make the site serve a defaced or error page to all users.
Published on github.com
History
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.
Context
The target is a web application that the researcher refers to as app.vulnerable.com throughout, because the program asked that the real asset not be disclosed. The application sits behind CloudFront, which caches responses at the front end and serves the cached copy to every user who requests the same resource. The researcher describes the environment as a staging environment rather than production.
The behaviour that makes the finding interesting is that the cache key at this host is unusually narrow. Neither the query string nor the path participates in it, and almost no request headers do either. That means a response cached for https://app.vulnerable.com/ is handed out for a much wider set of requests than an attacker would normally expect, and it also means the usual tricks for forcing a cache miss do not work.
Setup
The write-up does not describe any account, role or special tooling. Testing was done with curl against the live host, and the researcher notes that permission was obtained before poisoning the staging environment in real time. The only precondition that matters is timing: the poisoning step has to be launched at the moment the existing cache entry expires.
Finding it
While browsing https://app.vulnerable.com, the researcher concluded that a crafted request could have its response stored by CloudFront and then served to legitimate users. The difficulty was not in the poisoning itself but in demonstrating it inside the testing scope, because the cache key transformation removes most of the inputs an attacker would use to isolate a test from real traffic. The report breaks this down into three challenges.
Challenge #1: the query string is not part of the cache key
GET parameters do not act as cache keys. A request to https://app.vulnerable.com/?DontPoisonEveryone=true retrieves the cache stored for https://app.vulnerable.com/, so a poisoning attempt hidden behind a query parameter stays invisible. The flip side is worse: once the cache for https://app.vulnerable.com/ has expired, poisoning through https://app.vulnerable.com/?DontPoisonEveryone=true also poisons https://app.vulnerable.com/ and therefore affects genuine users. There is no safe cache buster in the query string.
Challenge #2: the path is not part of the cache key either
Requesting https://app.vulnerable.com/anything, where anything is not a static file endpoint, returns HTTP/1.1 200 OK as a cache HIT containing the response stored for https://app.vulnerable.com/. Because of this, path normalisation tricks using // or %2F do not produce a cache MISS. The researcher points to the "Unkeyed Query Detection" section of the PortSwigger web cache entanglement research as the relevant background.
Challenge #3: headers are unkeyed, with one narrow exception
No other request header, including Origin, is part of the cache key. The single exception is Accept-Encoding with a one-character value, which reaches the back end and produces a cache MISS, but only once. Sending Accept-Encoding: g, where g is any single alphanumeric character, acts as a cache buster; afterwards Accept-Encoding: a or Accept-Encoding: bbb do not, and the response cached against Accept-Encoding: g is returned instead. The practical consequence is that if the first request using Accept-Encoding: g is sent without the unkeyed header that performs the actual poisoning, the opportunity is lost until the cache entry for Accept-Encoding: g expires.
Exploitation
Step 1: prove the cache stores error responses
Using the single-shot cache buster from Challenge #3, the researcher sent a request with Accept-Encoding: g together with the unkeyed header, which produced an HTTP/1.1 400 Bad Request response. A victim then has to request the asset with Accept-Encoding: g as well. The conclusion is that the cache was poisoned for any user sending that header value, and the small test proved that the cache server is willing to store 400 responses, which is the actual vulnerability.
This approach was not appealing for targeting real users, and the report was initially closed as N/A.
Step 2: poison the staging host directly
The remaining option was to poison https://app.vulnerable.com itself. The Age and max-age response headers show that a cache entry lives for 21600 seconds (6 hours), of which Age seconds have already elapsed. The attacker waits until Age reaches max-age and immediately sends the following request:
curl --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" --compressed --header "Accept-Language: en-US,en;q=0.5" --header "Connection: close" --header "DNT: 1" --header "Sec-Fetch-Dest: document" --header "Sec-Fetch-Mode: navigate" --header "Sec-Fetch-Site: none" --header "Sec-Fetch-User: ?1" --header "Upgrade-Insecure-Requests: 1" --user-agent "Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0" --header "x-amz-server-side-encryption: PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh" -v https://app.vulnerable.com/
The request includes a set of browser-style headers, and the unkeyed header x-amz-server-side-encryption holds a long repeated string. Because that header is not part of the cache key, the response generated for this request is stored under the key for https://app.vulnerable.com/ and served to everyone else.
Step 3: observe the effect on genuine users
Any genuine user visiting https://app.vulnerable.com then sees the message PoC-by-AnkitSingh instead of the intended HTTP/1.1 200 OK response. The application portal before poisoning looked like this:
After poisoning it looked like this:
After permission was granted to poison the staging host in real time, and after a PoC video and further guidance were provided to the triage team, the report state changed:
The earlier N/A closure is shown here:
The researcher notes that convincing the program and triage team of the threat and impact would have been extremely difficult if the target had been a production application.
Root cause
The cache key at this host is built from almost nothing: the query string is excluded, the path is excluded for non-static endpoints, and request headers other than a single-character Accept-Encoding value are excluded. Any response the front end decides to store is therefore reused across a very wide range of requests, and an unkeyed input can change what other users receive. The second part of the problem is that the cache stores error responses such as HTTP/1.1 400 Bad Request, so a malformed or rejected request can still become the cached copy served to the next visitor. The report does not describe the origin code or the cache configuration responsible.
Impact
An attacker who can time a request to cache expiry can replace the page served at https://app.vulnerable.com/ for other users, in this case with the text PoC-by-AnkitSingh. The researcher describes the capability as disabling or defacing the application. The effect lasts for the lifetime of the poisoned cache entry, which the headers put at 21600 seconds for the cache. The researcher also stresses that the demonstration depended on the target being a staging environment, and that the same impact would have been harder to argue for a production system.
Fix
Based on the behaviour described, the cache key should include the full path and the query string, and responses that depend on request headers should either vary on those headers or not be cached at all. Error responses such as 400 should not be stored and served to other clients.
Variants to test
- Send a request with a query parameter that is reflected in the response and check whether a second request without the parameter returns the reflected value. A positive result is the injected value appearing in a response you did not send it in.
- Request a non-existent path such as
/anythingand compare the body and cache status with/. A cache HIT returning the root page shows the path is unkeyed. - Try
//and%2Fpath normalisation and watch for a cache MISS. If the response is still a HIT, path-based cache busting is unavailable. - Send
Accept-Encodingwith a single character, then with a different single character, then with a longer value, and compare cache statuses. A MISS only on the first request indicates the one-shot buster described here. - Send an unkeyed header with a distinctive value and check whether it appears in the cached response served to a later request without that header. A positive result is the value surviving into another user's response.
- Trigger an error response, such as a 400, through an unkeyed input and then request the resource normally. A cached error page indicates the cache stores error responses.
- Read
Ageandmax-ageon the target and schedule a poisoning request for the momentAgereachesmax-age. A successful result is the injected content appearing immediately after expiry.
Reward
Severity assigned: P3. Bounty assigned: $1000.
What happened, in plain words
A security researcher found that a website could be made to show a message of his choosing to every visitor, not just to himself. The site was a test copy of a real application, which the report calls app.vulnerable.com so the real name stays private. The trick is called web cache poisoning. To understand it, imagine a coffee shop with a tray of ready-made drinks by the counter. The barista makes one drink and puts it on the tray; every customer who orders the same thing gets a cup from the tray instead of a fresh one. A cache is that tray: a computer in front of the website keeps a copy of a page it has already built, and hands that copy to the next people who ask for it. If an attacker can slip a bad cup onto the tray, everyone after them gets the bad cup. That is what happened here: one crafted request put a page containing the text PoC-by-AnkitSingh onto the tray, and ordinary visitors saw it instead of the real page.
The report was paid a $1000 bounty at severity P3. The researcher is Ankit Singh (@AnkitCuriosity).
The pieces involved
Before the steps, here are the parts of the picture, explained from zero.
- Web application: a program you use through your browser. You type an address, your browser asks a server for a page, and the server sends back HTML (the language pages are written in) which the browser draws on screen.
- CloudFront: Amazon's content delivery network. A content delivery network is a set of computers placed between visitors and the real website. It keeps copies of pages so that visitors get answers quickly and the real server is not asked the same thing a thousand times. In this report CloudFront is the front end that holds the cache.
- Cache: the stored copy of a page. When the front end has a fresh copy, it answers from the copy; that is called a cache HIT. When it does not, it asks the real server behind it (the back end or origin) and may store the answer; that is a cache MISS.
- Cache key: the label under which a stored copy is filed. Think of a cloakroom: the ticket you get back depends on the label on your coat. If the label is just "coat", everyone gets whichever coat was hung first. Here the label was extremely broad: the query string and the path were not part of it, so many different requests were filed under the same label.
- Query string: the part of a web address after a question mark, such as
?DontPoisonEveryone=true. Websites often use it to pass small pieces of information, like a search term or a page number. - Path: the part of the address after the domain name, such as
/anythinginhttps://app.vulnerable.com/anything. - Request header: extra lines your browser sends along with the address, such as which language you prefer or what kind of browser you use. They are like the notes attached to an order.
- Unkeyed input: a piece of the request that the cache does not use when filing the response. If the page content depends on that piece but the filing label does not, an attacker can change the content while still landing in the same slot on the tray. That is the heart of cache poisoning.
- Cache buster: a small change to a request made on purpose so that the cache treats it as new and goes to the real server (a MISS). Testers use it to avoid disturbing real visitors while they experiment.
curl: a command-line tool for sending web requests by hand. You type a command in a terminal and it prints the server's answer. It lets you set headers a browser would not normally let you set.- Staging environment: a copy of the website used for testing, separate from the live one that real customers use (production). Breaking staging is much less harmful than breaking production.
- HTTP status codes: three-digit numbers a server sends to say how the request went.
200 OKmeans success;400 Bad Requestmeans the server did not like the request. Ageandmax-age: two headers about the stored copy.max-agesays how many seconds a stored copy is allowed to live;Agesays how many seconds have passed since it was stored. WhenAgereachesmax-age, the copy is stale and the next request goes to the real server.
The finding
While looking at https://app.vulnerable.com, the researcher concluded that a crafted request could have its response stored by CloudFront and then served to legitimate users. The hard part was not the poisoning itself but proving it inside the allowed testing scope, because the cache key throws away most of the inputs a tester would use to keep an experiment away from real traffic. The report splits this into three challenges.
Challenge #1: the query string is not part of the cache key
GET parameters (the name-value pairs in a query string) do not act as cache keys. A request to https://app.vulnerable.com/?DontPoisonEveryone=true retrieves the copy stored for https://app.vulnerable.com/, so a poisoning attempt hidden behind a query parameter stays invisible. The flip side is worse: once the copy for https://app.vulnerable.com/ has expired, poisoning through https://app.vulnerable.com/?DontPoisonEveryone=true also poisons https://app.vulnerable.com/ and therefore affects genuine users. There is no safe cache buster in the query string.
In everyday terms: you cannot write a different name on the cloakroom ticket to get a separate hook. Every ticket points at the same hook.
Challenge #2: the path is not part of the cache key either
Requesting https://app.vulnerable.com/anything, where anything is not a static file endpoint (a fixed file such as an image), returns HTTP/1.1 200 OK as a cache HIT containing the response stored for https://app.vulnerable.com/. Because of this, path normalisation tricks using // or %2F do not produce a cache MISS. Path normalisation means writing the same address in a different but equivalent way, for example with a double slash or with %2F, which is the encoded form of a slash. The researcher points to the "Unkeyed Query Detection" section of the PortSwigger web cache entanglement research as the relevant background.
In everyday terms: asking for a different shelf still gets you the item from the same shelf, because the shop ignores which shelf you named.
Challenge #3: headers are unkeyed, with one narrow exception
No other request header, including Origin, is part of the cache key. Origin is a header browsers send to say which site a request comes from. The single exception is Accept-Encoding with a one-character value, which reaches the back end and produces a cache MISS, but only once. Accept-Encoding is the header in which a browser lists the compression formats it can handle, such as gzip. Sending Accept-Encoding: g, where g is any single alphanumeric character, acts as a cache buster; afterwards Accept-Encoding: a or Accept-Encoding: bbb do not, and the response cached against Accept-Encoding: g is returned instead. The practical consequence is that if the first request using Accept-Encoding: g is sent without the unkeyed header that performs the actual poisoning, the opportunity is lost until the cache entry for Accept-Encoding: g expires.
In everyday terms: you get one free ticket to the kitchen, and only if you use it on your very first try. After that, the counter keeps handing you the same cup.
Exploitation
Step 1: prove the cache stores error responses
Using the single-shot cache buster from Challenge #3, the researcher sent a request with Accept-Encoding: g together with the unkeyed header, which produced an HTTP/1.1 400 Bad Request response. A victim then has to request the asset with Accept-Encoding: g as well. The conclusion is that the cache was poisoned for any user sending that header value, and the small test proved that the cache server is willing to store 400 responses, which is the actual vulnerability.
Why this step: before claiming that a page can be replaced for everyone, you want a small, contained proof. Here the proof was that even an error page gets stored and handed out. That is like discovering the coffee shop will put a cup with a cracked lid on the tray and still serve it.
This approach was not appealing for targeting real users, and the report was initially closed as N/A (not applicable).
Step 2: poison the staging host directly
The remaining option was to poison https://app.vulnerable.com itself. The Age and max-age response headers show that a cache entry lives for 21600 seconds (6 hours), of which Age seconds have already elapsed. The attacker waits until Age reaches max-age and immediately sends the following request:
curl --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" --compressed --header "Accept-Language: en-US,en;q=0.5" --header "Connection: close" --header "DNT: 1" --header "Sec-Fetch-Dest: document" --header "Sec-Fetch-Mode: navigate" --header "Sec-Fetch-Site: none" --header "Sec-Fetch-User: ?1" --header "Upgrade-Insecure-Requests: 1" --user-agent "Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0" --header "x-amz-server-side-encryption: PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh-PoC-by-AnkitSingh" -v https://app.vulnerable.com/
Line by line, in plain words:
curl: the command-line tool that sends the request.--header "Accept: ...": tells the server which kinds of content the client accepts. The long list is the one a normal browser sends.--compressed: asks curl to accept compressed responses and decompress them for display.--header "Accept-Language: en-US,en;q=0.5": says the client prefers US English.--header "Connection: close": asks the server to close the connection after the response.--header "DNT: 1": the Do Not Track preference, a browser privacy signal.--header "Sec-Fetch-Dest: document": part of a set of headers browsers use to describe what the request is for; here, a page to display.--header "Sec-Fetch-Mode: navigate": says this is a navigation, meaning a person following a link or typing an address.--header "Sec-Fetch-Site: none": says the request did not originate from another site.--header "Sec-Fetch-User: ?1": says the navigation was started by the user.--header "Upgrade-Insecure-Requests: 1": tells the server the client would prefer a secure (HTTPS) version if one exists.--user-agent "Mozilla/5.0 ... Firefox/95.0": identifies the client as a Firefox browser on Windows. This is part of making the request look like a normal visit.--header "x-amz-server-side-encryption: PoC-by-AnkitSingh-...": the unkeyed header. Its value is the textPoC-by-AnkitSinghrepeated many times. Because this header is not part of the cache key, the response built for this request is filed under the label forhttps://app.vulnerable.com/and served to everyone else.-v: verbose mode, so curl prints the request and response details, including the status code and headers.https://app.vulnerable.com/: the address being requested.
Why this step: the earlier test only reached users who sent a special header. To affect ordinary visitors, the poisoned copy had to be filed under the plain address. That required waiting for the old copy to expire, because until then the cache would keep answering with the old page and never ask the real server.
Step 3: observe the effect on genuine users
Any genuine user visiting https://app.vulnerable.com then sees the message PoC-by-AnkitSingh instead of the intended HTTP/1.1 200 OK response. The application portal before poisoning looked like this:
After poisoning it looked like this:
After permission was granted to poison the staging host in real time, and after a proof-of-concept video and further guidance were provided to the triage team (the people who review security reports), the report state changed:
The earlier N/A closure is shown here:
The researcher notes that convincing the program and triage team of the threat and impact would have been extremely difficult if the target had been a production application.
Root cause
The cache key at this host is built from almost nothing: the query string is excluded, the path is excluded for non-static endpoints, and request headers other than a single-character Accept-Encoding value are excluded. Any response the front end decides to store is therefore reused across a very wide range of requests, and an unkeyed input can change what other users receive. Reflected means the value you sent appears in the page that comes back. The second part of the problem is that the cache stores error responses such as HTTP/1.1 400 Bad Request, so a malformed or rejected request can still become the cached copy served to the next visitor. The report does not describe the origin code or the cache configuration responsible.
Impact
An attacker who can time a request to cache expiry can replace the page served at https://app.vulnerable.com/ for other users, in this case with the text PoC-by-AnkitSingh. The researcher describes the capability as disabling or defacing the application. Defacing means changing what a site shows; disabling means making it unusable. The effect lasts for the lifetime of the poisoned cache entry, which the headers put at 21600 seconds for the cache. The report does not state which users or how many were affected, and it does not describe any data theft, account takeover or persistence beyond the cache lifetime. The researcher also stresses that the demonstration depended on the target being a staging environment, and that the same impact would have been harder to argue for a production system.
Fix
Based on the behaviour described, the cache key should include the full path and the query string, and responses that depend on request headers should either vary on those headers or not be cached at all. Error responses such as 400 should not be stored and served to other clients.
Variants to test
These are checks a beginner can repeat on a site they are allowed to test. Each one is a small experiment with a clear expected sign.
- Send a request with a query parameter that is reflected in the response and check whether a second request without the parameter returns the reflected value. A positive result is the injected value appearing in a response you did not send it in.
- Request a non-existent path such as
/anythingand compare the body and cache status with/. A cache HIT returning the root page shows the path is unkeyed. - Try
//and%2Fpath normalisation and watch for a cache MISS. If the response is still a HIT, path-based cache busting is unavailable. - Send
Accept-Encodingwith a single character, then with a different single character, then with a longer value, and compare cache statuses. A MISS only on the first request indicates the one-shot buster described here. - Send an unkeyed header with a distinctive value and check whether it appears in the cached response served to a later request without that header. A positive result is the value surviving into another user's response.
- Trigger an error response, such as a 400, through an unkeyed input and then request the resource normally. A cached error page indicates the cache stores error responses.
- Read
Ageandmax-ageon the target and schedule a poisoning request for the momentAgereachesmax-age. A successful result is the injected content appearing immediately after expiry.
Reward
Severity assigned: P3. Bounty assigned: $1000.
Glossary
- Back end (origin): the real web server behind a cache or content delivery network; it builds pages when the cache does not have a fresh copy.
- Cache: a store of saved responses that are reused instead of asking the server again.
- Cache buster: a deliberate change to a request so the cache treats it as new and forwards it to the server.
- Cache HIT: the cache had a stored copy and answered with it.
- Cache key: the label under which a response is stored; requests with the same key share the stored copy.
- Cache MISS: the cache had no usable copy and asked the server.
- CloudFront: Amazon's content delivery network, which caches responses close to visitors.
- Content delivery network (CDN): a network of servers placed between visitors and a website to speed up delivery and absorb traffic.
curl: a command-line program for sending HTTP requests and printing the responses.- Deface: to change what a website shows to its visitors.
- GET parameter: a name-value pair in the query string of a URL, used to pass small pieces of data.
- Header: an extra line of information sent with a request or response, such as language preference or content type.
- HTML: the language in which web pages are written.
- HTTP status code: a three-digit number in a response saying how the request went, such as 200 for success or 400 for a bad request.
max-age: a response header giving the number of seconds a stored copy may be used.Age: a response header giving the number of seconds since the stored copy was created.- Path: the part of a URL after the domain, such as
/anything. - Path normalisation: writing the same path in a different but equivalent form, for example with
//or%2F. - Production: the live website used by real customers.
- Query string: the part of a URL after
?, made of parameters. - Reflected: a value sent in a request that appears in the response.
- Staging environment: a test copy of a website, separate from production.
- Triage team: the people who review and rate security reports for a program.
- Unkeyed input: part of a request that the cache does not use when filing the response, so it can change the content without changing the cache key.
- Web cache poisoning: making a cache store a response an attacker controls, so other visitors receive it.