Chaining Cache Poisoning To Stored XSS
A Drupal application had its internal caching enabled by default, and an HTTP header named 'style' was reflected in responses. An attacker could poison the cache with an XSS payload, causing stored XSS for anyone visiting the poisoned URL.
Published on medium.com
#### Rohan Aggarwal
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 was a Drupal application found in a bug bounty program on HackerOne. The author does not name the program or the host; the poisoned URL in the write-up is shown as www.redacted.com. The feature involved is Drupal's own internal caching system, which is enabled by default. The write-up is about turning that caching into a vector for stored XSS by poisoning a cached response with a reflected header value.
The author's broader point is that knowing the framework or CMS behind an application changes what you look for. As an example he describes Rails developers who use Scaffold to generate models, views and controllers in one operation: Scaffold also creates a JSON API endpoint for each route, which developers often overlook or forget to remove in production. A developer who removed sensitive information from a normal route might leave the same information in the JSON endpoint of that route. The same reasoning applies to Drupal: knowing its defaults tells you which misconfigurations to check first.
Setup
The write-up does not describe any accounts, roles or application-specific configuration. The tooling used was Burp Suite with the Param Miner extension, which brute-forces common HTTP headers. The precondition for the whole attack is that Drupal's internal caching is enabled, which is the default.
Finding it
The author had used Drupal before, so he started looking for common Drupal misconfigurations and found one within 10 minutes.
The first check is whether caching is enabled. Drupal exposes this through the x-drupal-cache response header. The test is:
- Send a request with a unique key, meaning a unique combination of endpoint and parameters.
- The response carries
x-drupal-cache: MISS. - Send the same request again with the same key.
- The response now carries
x-drupal-cache: HIT, which confirms that caching is enabled.
With caching confirmed, the plan was to poison the cache with an XSS payload. That requires an HTTP header whose value is reflected in the response. Drupal, like other PHP frameworks, sometimes supports the X-Original-URL and X-Rewrite-URL headers because of Zend. The author tried injecting these headers, but the application did not accept them.
Rather than give up, he brute-forced headers with Param Miner. After a few seconds it found a hit: a header named style was reflected in the response. He checked whether the reflection was vulnerable to XSS and it was.
Exploitation
Step 1: confirm caching
Send a request with a unique key and observe x-drupal-cache: MISS, then repeat it and observe x-drupal-cache: HIT. This establishes that responses are cached per key and that a poisoned response will be stored and served to later visitors.
Step 2: find a reflected header
The X-Original-URL and X-Rewrite-URL attempts failed because the application did not accept them. Param Miner then identified the style header as reflected in the response, and the reflection was confirmed to be XSS-vulnerable.
Step 3: poison the cache
The author created a unique key, added the style header with an XSS payload, and sent the request. The write-up does not reproduce the exact header value or the full request.

The screenshot accompanies the step where the author created a unique key, added the style header with the XSS payload and fired the request.
Step 4: serve the poisoned response
The response containing the XSS payload is cached for that unique request. From then on, whenever someone visits the following URL, Drupal serves the poisoned response, which results in stored XSS:
The write-up gives this URL as the one that serves the poisoned response.
Root cause
Two conditions combine. First, Drupal's internal cache is enabled by default, so a response produced for one specific request is reused for later requests with the same key. Second, the application reflects the value of the style header into the response without sanitising it, so an attacker-controlled header value becomes attacker-controlled markup.
Because the reflected value is stored in the cache, the reflection stops being per-request: it is served to anyone who requests the poisoned key. The existing defences did not stop this. The application did not accept the X-Original-URL and X-Rewrite-URL headers, but the style header was reflected.
Impact
An attacker can turn a reflected header value into stored XSS for any user who requests the poisoned URL. The author frames this as a simple Drupal misconfiguration leading to stored XSS. The write-up does not describe what the payload did once executed, which users were affected, or any session or account impact.
Fix
The report was submitted on 14 June 2019, triaged on 15 June 2019, resolved on 12 July 2019 and rewarded on 13 July 2019. The fix itself is not described.
Variants to test
- Check for framework-specific cache headers. On Drupal, send a request with a unique key and look for
x-drupal-cache: MISS, then repeat it and look forx-drupal-cache: HIT. A positive result confirms that caching is enabled. - Try the framework headers first. Send
X-Original-URLandX-Rewrite-URLand see whether the application accepts them. A positive result is a change in routing or content that follows the header value. - Brute-force header names with Param Miner on any endpoint that is cached. A positive result is any header whose value appears in the response body.
- For each reflected header, test whether the reflection is XSS-vulnerable by sending markup in the header value and checking whether it is returned unencoded. A positive result is executable markup in the response.
- Combine the two: send the vulnerable header with a payload on a unique cache key, then request the same key without the header. A positive result is the payload being served from cache to the second request, which is the stored XSS condition.
What happened, in plain words
A security researcher found a website built with a popular tool called Drupal. Drupal has a built-in feature that saves copies of pages so they load faster for the next visitor. The researcher discovered that the site also took a value from a request header (a small piece of extra information sent with every web request) and pasted it into the page without cleaning it. By combining these two things, he was able to make the saved copy of a page contain a malicious script. Anyone who later visited that exact page would receive the malicious script, which is a type of attack called stored cross-site scripting (XSS).
This article explains the whole chain step by step, assuming you know nothing about security. You only need to know how to use a browser and a computer.
Background: why knowing the framework helps
The author starts with a general point: if you know what software a website is built with, you can guess how it works and where mistakes are likely. He gives an example from the Ruby on Rails framework. Rails developers often use a tool called Scaffold to quickly create the main parts of an application: models (data structures), views (what you see) and controllers (logic). Scaffold also automatically creates a JSON API endpoint for each route. An API is a way for programs to talk to each other; a JSON API returns data in a format called JSON, which is easy for programs to read. Developers often forget to remove these automatically created endpoints when they put the site live. So a developer might carefully hide sensitive information on the normal page but leave the same information exposed in the JSON endpoint. Knowing this, a tester can check for it and find things others miss.
The same idea applies to Drupal. Drupal is a content management system (CMS): software that lets people build and manage websites without writing all the code from scratch. It has its own way of doing things, and some of its default settings can be risky if not understood. The author had used Drupal before, so he knew what to look for.
Finding the target and the first clue
The researcher was taking part in a bug bounty program on HackerOne. A bug bounty program is a scheme where organisations pay people to find and report security problems in their systems. The program and the real website address are not named in the write-up; the site is shown as www.redacted.com. The author says he found a misconfiguration within 10 minutes.
The first thing he checked was whether Drupal's internal caching was turned on. Caching means storing a copy of a page so that the next request for the same page can be served faster, without rebuilding it. Drupal enables its cache by default. To check, you look at the response headers. Headers are extra pieces of information that come with every web response, like the label on a parcel. Drupal adds a header called x-drupal-cache. The test works like this:
- Send a request with a unique key. A key here means a unique combination of the endpoint (the address you are requesting) and its parameters (the extra bits after the
?in a URL). - The response will include the header
x-drupal-cache: MISS. "MISS" means the page was not found in the cache, so it was built fresh. - Send exactly the same request again.
- This time the response includes
x-drupal-cache: HIT. "HIT" means the page was found in the cache and served from it. This confirms caching is enabled.
The author links to a well-known article by albinowax on practical web cache poisoning for further reading. Cache poisoning is the attack of putting something harmful into the cache so that later visitors receive it.
Trying to poison the cache
With caching confirmed, the plan was to poison the cache with an XSS payload. XSS, or cross-site scripting, is a vulnerability where an attacker can make a website display their own code (usually JavaScript) to other users. When that code runs in a victim's browser, it can do things like steal cookies (small files websites store in your browser to remember you) or perform actions as the victim. A payload is the actual code or data used in an attack.
To poison the cache, the attacker needs a way to get their payload into the cached page. One common way is to find an HTTP header whose value is reflected in the response. "Reflected" means the server takes the value from the request and includes it in the page it sends back, without changing it. If the value is not cleaned (sanitised), it can become part of the page's code.
The author knew that Drupal, like some other PHP frameworks, sometimes supports special headers called X-Original-URL and X-Rewrite-URL. These headers can change how the server routes a request. He tried sending these headers, but the application did not accept them. So that route was closed.
Brute-forcing headers
When a direct approach fails, the author suggests trying brute force. Brute force means trying many possibilities systematically until one works. He used a Burp Suite extension called Param Miner. Burp Suite is a tool for testing web applications, and Param Miner is an add-on that automatically tries many common HTTP header names to see if any affect the response.
After a few seconds, Param Miner found a hit: a header named style was being reflected in the response. The author then checked whether that reflection was vulnerable to XSS, and it was. That means the value of the style header was inserted into the page in a way that allowed executable code.
Exploiting the vulnerability
Step 1: confirm caching
The author had already confirmed caching by seeing x-drupal-cache: MISS on the first request and x-drupal-cache: HIT on the second. This matters because it shows that responses are stored per key and that a poisoned response will be served to later visitors who use the same key.
Step 2: find a reflected header
The attempts with X-Original-URL and X-Rewrite-URL failed because the application did not accept them. Param Miner then identified the style header as reflected, and the author confirmed the reflection was XSS-vulnerable.
Step 3: poison the cache
The author created a unique key, added the style header with an XSS payload, and sent the request. The exact header value and the full request are not reproduced in the write-up.

The screenshot accompanies the step where the author created a unique key, added the style header with the XSS payload and fired the request.
Step 4: serve the poisoned response
The response containing the XSS payload is now cached for that unique request. From then on, whenever someone visits the following URL, Drupal serves the poisoned response, resulting in stored XSS:
The write-up gives this URL as the one that serves the poisoned response.
Why it worked
Two conditions combined. First, Drupal's internal cache is enabled by default, so a response produced for one specific request is reused for later requests with the same key. Second, the application reflects the value of the style header into the response without sanitising it, so an attacker-controlled header value becomes attacker-controlled markup.
Because the reflected value is stored in the cache, the reflection stops being per-request: it is served to anyone who requests the poisoned key. The existing defences did not stop this. The application did not accept the X-Original-URL and X-Rewrite-URL headers, but the style header was reflected.
Impact
An attacker can turn a reflected header value into stored XSS for any user who requests the poisoned URL. The author frames this as a simple Drupal misconfiguration leading to stored XSS. The write-up does not describe what the payload did once executed, which users were affected, or any session or account impact.
Fix
The write-up does not say what was changed to resolve the issue. The report was submitted on 14 June 2019, triaged on 15 June 2019, resolved on 12 July 2019 and rewarded on 13 July 2019. The fix itself is not described.
Variants to test
- Check for framework-specific cache headers. On Drupal, send a request with a unique key and look for
x-drupal-cache: MISS, then repeat it and look forx-drupal-cache: HIT. A positive result confirms that caching is enabled. - Try the framework headers first. Send
X-Original-URLandX-Rewrite-URLand see whether the application accepts them. A positive result is a change in routing or content that follows the header value. - Brute-force header names with Param Miner on any endpoint that is cached. A positive result is any header whose value appears in the response body.
- For each reflected header, test whether the reflection is XSS-vulnerable by sending markup in the header value and checking whether it is returned unencoded. A positive result is executable markup in the response.
- Combine the two: send the vulnerable header with a payload on a unique cache key, then request the same key without the header. A positive result is the payload being served from cache to the second request, which is the stored XSS condition.
Glossary
- API: Application Programming Interface; a way for two programs to communicate, often returning data in a structured format like JSON.
- Brute force: Trying many possibilities systematically until one works.
- Bug bounty program: A scheme where organisations reward people for finding and reporting security vulnerabilities.
- Burp Suite: A tool for testing web applications, often used to intercept and modify requests.
- Cache: A temporary storage area that holds copies of data so future requests can be served faster.
- Cache poisoning: An attack where harmful data is placed into a cache so that later visitors receive it.
- CMS: Content Management System; software for building and managing websites.
- Cookie: A small piece of data stored by a website in a user's browser to remember information about the user.
- Cross-site scripting (XSS): A vulnerability that allows an attacker to inject malicious scripts into web pages viewed by other users.
- Drupal: A popular open-source content management system.
- Endpoint: A specific URL or address that a web application responds to.
- Framework: A pre-built set of tools and libraries that developers use to build applications faster.
- HackerOne: A platform that hosts bug bounty programs.
- Header: Extra information sent with an HTTP request or response, such as the type of content or caching instructions.
- JSON: A lightweight data format that is easy for humans to read and for machines to parse.
- Param Miner: A Burp Suite extension that brute-forces HTTP header names and parameters.
- Payload: The code or data used in an attack to achieve a goal, such as executing JavaScript.
- PHP: A programming language commonly used for web development.
- Reflected: When a value from a request is included in the response without being stored.
- Sanitise: To clean or encode data so that it cannot be interpreted as code.
- Scaffold: A Rails feature that generates models, views, controllers and JSON endpoints automatically.
- Stored XSS: A type of XSS where the malicious script is saved on the server (e.g. in a cache or database) and served to multiple users.
- Triaged: The process of reviewing a reported vulnerability to determine its validity and severity.
- Unique key: A combination of endpoint and parameters that uniquely identifies a cached response.
- X-Original-URL / X-Rewrite-URL: HTTP headers that can sometimes override the requested URL and affect routing.
- x-drupal-cache: A response header added by Drupal that indicates whether the response was served from cache (HIT) or not (MISS).