Skip to content
Cache bugs Disclosed report Intermediate

Denial-of- service By Cache Poisoning The Cross-Origin Resource Sharing Misconfiguration Allow Origin Header

The WordPress wp-json API echoes the request's Origin header into Access-Control-Allow-Origin and caches the response without keying on Origin. An attacker could poison the cache so that legitimate cross-origin requests from a frontend fail the CORS check, causing a denial of service for that frontend.

hannanhaseeb Follow

Originally disclosed on HackerOne

  • Triaged in 3 days
  • Fixed in 3 days
  • Paid in 3 days
  • Disclosed after 33 days

Summery:

The wp-json implementation on some WordPress websites I've tested is vulnerable to Denial-of-service where by an attacker can provide an arbitrary origin header in the request, which is then echoed back in the response via the Access-Control-Allow-Origin header, which is cached and served to other requests. This response header is used by browsers to determine whether the requesting origin is allowed to read the response in the request. In the event the victim website had another origin that used the wp-json API to request data from their WordPress site, this cache poisoning would deny access to such requests due to failed a Cross-Origin Resource Sharing access control check. It appears that this vulnerability is only a concern if the wp-json API responses are cached, which you can determine by the presence of a X-Cache: hit header in the response.

Description:

How does this lead to a Denial-of-service? Well, consider the possibility that this WordPress site is the back end of a headless or decoupled CMS style web application. While custom frontends unrestricted by the CMS theming engine are used as the presentation layer to the user, and communication between the two is often achieved via some sort of API and front end JavaScript framework pairing. What I have been requesting above is one such API, and it turns out WordPress has had this REST like JSON API called wp-json API inbuilt into its core package since v4.7, so you could say out of the box WordPress is ready to be used as a headless CMS. If by some chance the front end of the application in question happens to sit in a different origin than the WordPress site for instance www.site.com for the frontend and www.api.site.com for the WordPress instance, then the front end would require Cross-Origin Resource Sharing to be configured to allow it access to wp-json API, and this cache poisoning vulnerability could impact the availability of such an application, as the mismatch between a legitimate origin value in a request compared to the attacker's poisoned Access-Control-Allow-Origin value in the response will result in an error like in the following screenshot.

Steps To Reproduce:

For this test, I'm going to target site, a WordPress site. I will be doing this with a cache busting technique that doesn't really poison the live site's cache by supplying a bespoke query string value so this should be safe to repeat verbatim.

  • First open an HTTPS website, it doesn't matter which website, as long as it trigger browser Cross-Origin Resource Sharing. For my test, I used this website.
  • Open the JavaScript console and execute the following command 5 to 10 times to make sure the cache is poisoned across back end. You can also do this Burp Suite by sending request multiple times.
JavaScript
fetch('https://en.instagram-brand.com/wp-json/').then(res => res.json()).then(json => console.log(json))
  • Now, open another HTTPS website, it also doesn't matter which site it is, as long as it's execute the same fetch as above.
  • You should now experience a Cross-Origin Resource Sharing error in your browser console while fetching.
  • What's going on here? because the wp-json response is Cross-Origin Resource Sharing aware, it is responding with a Access-Control-Allow-Origin header value. Presumably to offer wide support for Cross-Origin Resource Sharing, the origin value in the request is being echoed back. So far, I believe this is standard WordPress wp-json behavior. However, WordPress is caching this response and is not keying the cache based on the request origin value, so therefore is serving the poisoned response, and because the other origin is not previous one, Cross-Origin Resource Sharing in the browser blocks the response coming back into the Document Object Model.

Reference:

Please click on the following blog post link and report link with the same issue for more information.

Mitigation:

I believe to fix this you should make sure that edge caches for wp-json requests are using the origin header in the request to key the cache, so one value can't affect the cache served to another value. Preventing the echoing back of the Origin into the Access-Control-Allow-Origin response header without first passing through a configurable white list would also be a potential solution, but this may be harder to implement.

Impact

The impact of this vulnerability depends on how and where a client uses the wp-json plugin. If a WordPress customer uses wp-json in a context that relies on Cross-Origin Resource Sharing, this technique could deny service to the wp-json endpoints in use.

Attachments

Screencast_07-12-2020_02_57_09_PM.webm From the original on HackerOne

The original report as published on HackerOne, by hannanhaseeb. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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. 5 min read.

Context

The target is the wp-json REST API that ships in WordPress core. The researcher notes that WordPress has included this REST-like JSON API in its core package since v4.7, which means a stock WordPress install can be used as the back end of a headless or decoupled CMS: a custom front end, unrestricted by the CMS theming engine, acts as the presentation layer and talks to WordPress over the API.

The feature that matters here is Cross-Origin Resource Sharing. When the front end and the WordPress instance sit on different origins, for example www.site.com for the front end and www.api.site.com for WordPress, the browser will only let the front end read wp-json responses if the server sends a suitable Access-Control-Allow-Origin header. The researcher observed that the wp-json implementation on some WordPress sites echoes the request's Origin value back in that header, and that the response is then cached and served to other requests.

Setup

No accounts or special roles are involved. The researcher tested against a live WordPress site, https://en.instagram-brand.com/wp-json, from ordinary HTTPS websites opened in a browser, using the JavaScript console. Burp Suite is mentioned as an alternative way to send the request repeatedly. The only precondition is that the wp-json responses are cached; the researcher says you can determine this by the presence of an X-Cache: hit header in the response.

To keep the test safe to repeat, the researcher used a cache busting technique: supplying a bespoke query string value so the live site's cache is not really poisoned.

Finding it

The wp-json response is CORS aware and returns an Access-Control-Allow-Origin header. Presumably to offer wide support for CORS, the origin value from the request is echoed back. The researcher believes this echoing is standard WordPress wp-json behaviour. What looked wrong was the combination with caching: WordPress caches the response and does not key the cache on the request's origin value, so a response carrying one origin's value is served to requests coming from a different origin. Because the origin in the poisoned response does not match the requesting origin, the browser's CORS check fails and the response is blocked from reaching the Document Object Model.

Exploitation

Step 1: pick an HTTPS page to send the request from

Open an HTTPS website; it does not matter which one, as long as it triggers browser CORS. The researcher used https://www.shawarkhan.com/.

Step 2: send the cross-origin fetch repeatedly

Open the JavaScript console and execute the following command 5 to 10 times to make sure the cache is poisoned across the back end. The same can be done in Burp Suite by sending the request multiple times.

JavaScript
fetch('https://en.instagram-brand.com/wp-json/').then(res => res.json()).then(json => console.log(json))

The fetch issues a cross-origin request to the wp-json endpoint from the page the console belongs to. The server echoes that value into Access-Control-Allow-Origin and caches the response.

Step 3: send the same fetch from a different origin

Open another HTTPS website, again any site, as long as it executes the same fetch as above.

Step 4: observe the CORS error

You should now experience a CORS error in the browser console while fetching. The cached response carries the first origin's Access-Control-Allow-Origin value, which does not match the second origin, so the browser blocks the response.

Screencast_07-12-2020_02_57_09_PM.webm From the original on HackerOne

Root cause

The origin value in the request is echoed back in Access-Control-Allow-Origin, and the response is cached without the request origin being part of the cache key. The cache therefore serves a response whose Access-Control-Allow-Origin belongs to a different origin than the one asking. The browser compares the two, the check fails, and the response is discarded before it reaches the DOM.

The echoing appears to be intended CORS behaviour, and the cache is not keyed on the request origin. The researcher notes that the issue is only a concern if the wp-json API responses are cached.

Impact

The impact depends on how and where a client uses the wp-json API. If a WordPress customer uses wp-json in a context that relies on CORS, this technique could deny service to the wp-json endpoints in use. The clearest case is a headless or decoupled CMS whose front end sits on a different origin from the WordPress instance: the mismatch between the legitimate origin in the request and the attacker's poisoned Access-Control-Allow-Origin value in the response produces an error, and the front end can no longer read the API. The researcher frames this as a denial of service affecting availability.

Fix

The researcher proposes two options:

  1. Make sure edge caches for wp-json requests use the Origin header in the request to key the cache, so one value cannot affect the cache served to another value.
  2. Prevent the echoing of Origin into the Access-Control-Allow-Origin response header without first passing it through a configurable white list. The researcher notes this may be harder to implement.
  • Other WordPress sites with cached wp-json responses. Send the cross-origin fetch from one origin, then repeat it from a second origin. A positive result is a CORS error on the second request and an Access-Control-Allow-Origin value matching the first origin. Check for X-Cache: hit to confirm caching is in play.
  • Other API endpoints that echo Origin. Apply the same two-origin test to any endpoint that reflects the request origin into Access-Control-Allow-Origin. A positive result is the same mismatch between the reflected value and the requesting origin.
  • Cache key behaviour. Vary only the Origin header between requests to the same URL and observe whether the cached response changes. If it does not, the origin is not part of the cache key.
  • Headless or decoupled deployments. Where a front end on one origin consumes a WordPress API on another, test whether poisoning the cache breaks the front end's API calls. A positive result is the front end failing its CORS check after the cache is poisoned.

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. 10 min read.

What happened, in plain words

A website can be built in two separate pieces. One piece is the part you see and click on, the pages and buttons. The other piece is a server that stores the content and hands it out when asked. The two pieces talk to each other over the internet through something called an API. Think of an API as a waiter in a restaurant: you do not walk into the kitchen yourself, you tell the waiter what you want and the waiter brings it back. The front end is the customer, the API is the waiter, and the WordPress server is the kitchen.

WordPress, the software many sites are built on, has a built-in API called wp-json. It has shipped inside WordPress since version 4.7, so a plain WordPress install can already act as the kitchen for a separate front end. This setup is often called a headless or decoupled CMS: the content management system (the kitchen) is separated from the presentation layer (the dining room).

The problem in this report is about what happens when the front end and the WordPress server live at different web addresses, called origins. A browser has a security rule that stops a page at one origin from freely reading data from another origin. That rule is called Cross-Origin Resource Sharing, or CORS. To let a trusted front end read the API, the server has to send back a header (a small piece of information attached to the response) saying which origin is allowed. That header is Access-Control-Allow-Origin.

The researcher found that some WordPress sites simply copy whatever origin the request came from into that header, and then store (cache) the response. Caching means keeping a copy of an answer so the next person gets it faster, like a restaurant keeping a few plates already made up. The stored copy is then handed to everyone who asks, even people from a different origin. Their browser sees an allow-header naming someone else's origin, decides the answer is not for them, and blocks it. The front end can no longer read the API. That is a denial of service: the site is not broken or hacked for data theft, it just stops being usable for the legitimate front end.

This only matters if the wp-json responses are actually cached. The researcher says you can tell by looking for an X-Cache: hit header in the response.

The setup

No accounts, logins or special permissions are needed. The researcher tested against a live WordPress site, https://en.instagram-brand.com/wp-json, from ordinary HTTPS websites opened in a normal browser, using the browser's JavaScript console. HTTPS is the padlock version of the web, where traffic is encrypted. The JavaScript console is a panel built into every browser where you can type commands and see the results; it is normally hidden behind the developer tools.

Burp Suite is mentioned as an alternative: it is a tool that lets you capture and resend web requests by hand, so you can repeat the same request many times without typing in the console.

The one precondition is that the wp-json responses are cached. If they are not cached, there is no stored copy to poison and nothing to serve to the wrong visitor.

To keep the test safe to repeat, the researcher used a cache busting technique. Cache busting means adding a small unique value to the address (a query string value) so the cache treats it as a new request rather than overwriting the real site's stored copy. In plain terms: the researcher made sure the experiment did not damage the live site's cache for ordinary visitors.

Finding it

The wp-json response is CORS aware, meaning it knows about the cross-origin rule and sends back an Access-Control-Allow-Origin header. Presumably to support as many front ends as possible, the server copies the origin value from the request straight into that header. The researcher believes this copying is standard WordPress wp-json behaviour.

What looked wrong was the combination with caching. WordPress stores the response and does not include the request's origin value when deciding which stored copy to hand out. In everyday terms: the restaurant keeps one plate under a label that says "for table 5", and then serves that same plate to table 9 as well. The browser at table 9 checks the label, sees it is not for them, and refuses the plate. The response is blocked before it reaches the Document Object Model, which is the browser's internal model of the page; if the data never gets there, the page's JavaScript cannot use it.

Exploitation

Step 1: pick an HTTPS page to send the request from

Open any HTTPS website. It does not matter which one, as long as it triggers browser CORS. The researcher used https://www.shawarkhan.com/. The site must trigger browser CORS, which is why any HTTPS website works. You need a page with an origin of its own to make that comparison happen.

Step 2: send the cross-origin fetch repeatedly

Open the JavaScript console on that page and run the following command 5 to 10 times, to make sure the cache is poisoned across the back end. The same can be done in Burp Suite by sending the request multiple times.

JavaScript
fetch('https://en.instagram-brand.com/wp-json/').then(res => res.json()).then(json => console.log(json))

Line by line, in plain words:

  • fetch('https://en.instagram-brand.com/wp-json/') asks the browser to go and get the address in the brackets. fetch is the browser's built-in way of making a request from JavaScript. Because the page you are on and that address are different origins, the browser treats this as a cross-origin request and attaches an Origin header saying where the request came from.
  • .then(res => res.json()) says: when the answer arrives, take it (res) and read its body as JSON. JSON is a common text format for structured data, a bit like a very strict shopping list.
  • .then(json => console.log(json)) says: when that is done, print the result in the console so you can see it.

Running it several times is meant to make sure the cache is poisoned across the back end. The server copies your origin into Access-Control-Allow-Origin and caches the response.

Step 3: send the same fetch from a different origin

Open another HTTPS website, again any site, as long as it runs the same fetch as above. The point is that this second page has a different origin from the first. The browser will now ask for the same wp-json address, but this time the stored answer already exists.

Step 4: observe the CORS error

You should now see a CORS error in the browser console while fetching. The stored response carries the first origin's Access-Control-Allow-Origin value, which does not match the second origin, so the browser blocks the response. Nothing is wrong with the network or the server; the browser is doing exactly its job, protecting the second page from reading an answer that was addressed to someone else.

Screencast_07-12-2020_02_57_09_PM.webm From the original on HackerOne

Why it happens

The origin value in the request is copied back in Access-Control-Allow-Origin, and the response is cached without the request origin being part of the cache key. The cache key is the label the cache uses to decide which stored copy matches which request, like the table number on a restaurant order. If the origin is not on that label, one origin's answer gets served to another origin. The browser compares the two origins, the check fails, and the response is thrown away before it reaches the page.

The copying appears to be intended CORS behaviour, and the cache is not keyed on the request origin. The researcher notes the issue is only a concern if the wp-json API responses are cached.

Impact

The impact depends on how and where a client uses the wp-json API. If a WordPress customer uses wp-json in a context that relies on CORS, this technique could deny service to the wp-json endpoints in use. The clearest case is a headless or decoupled CMS whose front end sits on a different origin from the WordPress instance: the mismatch between the legitimate origin in the request and the attacker's poisoned Access-Control-Allow-Origin value in the response produces an error, and the front end can no longer read the API. The researcher frames this as a denial of service affecting availability. In other words, the attacker does not steal anything; they make the site's own front end unable to talk to its own back end.

Fix

The researcher proposes two options:

  1. Make sure edge caches for wp-json requests use the Origin header in the request to key the cache, so one value cannot affect the cache served to another value. An edge cache is a cache that sits close to visitors, often run by a content delivery network, to speed up responses. Putting the origin on the label means each origin gets its own stored copy.
  2. Prevent the copying of Origin into the Access-Control-Allow-Origin response header without first passing it through a configurable white list. A white list is a fixed list of things you allow, like a guest list at a door: only origins on the list get named in the header. The researcher notes this may be harder to implement.
  • Other WordPress sites with cached wp-json responses. Send the cross-origin fetch from one origin, then repeat it from a second origin. A positive result is a CORS error on the second request and an Access-Control-Allow-Origin value matching the first origin. Check for X-Cache: hit to confirm caching is in play.
  • Other API endpoints that copy Origin. Apply the same two-origin test to any endpoint that reflects the request origin into Access-Control-Allow-Origin. A positive result is the same mismatch between the copied value and the requesting origin.
  • Cache key behaviour. Change only the Origin header between requests to the same URL and observe whether the cached response changes. If it does not, the origin is not part of the cache key.
  • Headless or decoupled deployments. Where a front end on one origin consumes a WordPress API on another, test whether poisoning the cache breaks the front end's API calls. A positive result is the front end failing its CORS check after the cache is poisoned.

Glossary

  • API: a defined way for one piece of software to ask another for data or actions, like a waiter taking your order to the kitchen.
  • wp-json: the built-in REST-style API in WordPress core, available since version 4.7, which lets other software read and use a WordPress site's content.
  • WordPress: the content management software many websites are built on; it stores and serves the site's content.
  • Headless CMS / decoupled CMS: a setup where the content system and the visible front end are separate pieces that talk over an API.
  • Front end: the part of a site a visitor sees and interacts with.
  • Back end: the server-side part that stores data and answers requests.
  • Presentation layer: the visible layer of an application, the pages and interface.
  • Origin: the combination of scheme (http or https), host name and port that identifies where a web page or resource comes from. Two pages with different host names are different origins.
  • CORS (Cross-Origin Resource Sharing): the browser rule that stops a page at one origin from reading responses from another origin unless the server explicitly allows it.
  • Header: a small labelled piece of information sent along with a web request or response, such as which origin a request came from.
  • Origin header: the request header in which the browser states which origin the request is coming from.
  • Access-Control-Allow-Origin: the response header in which a server names the origin that is allowed to read the response.
  • X-Cache: hit: a response header indicating the answer came from a cache rather than being generated fresh.
  • Cache: a store of saved responses kept so future requests can be answered faster.
  • Cache key: the label a cache uses to decide which saved response matches which request.
  • Cache poisoning: making a cache store a malicious or wrong response so that other visitors receive it.
  • Cache busting: adding a unique value to a request so the cache treats it as new and does not overwrite or reuse the normal stored copy.
  • Denial of service (DoS): making a service unavailable to its legitimate users, without necessarily stealing data.
  • Availability: the property of a system being usable when legitimate users need it.
  • HTTPS: the encrypted version of web traffic, shown by the padlock in the browser.
  • JavaScript console: a panel in the browser's developer tools where you can type and run JavaScript and see its output and errors.
  • fetch: the browser's built-in JavaScript function for making a web request.
  • JSON: a common text format for structured data.
  • DOM (Document Object Model): the browser's internal representation of a page, which JavaScript reads and changes; data blocked by CORS never reaches it.
  • Burp Suite: a tool for capturing and resending web requests by hand.
  • Edge cache: a cache placed close to visitors, often by a content delivery network, to speed up responses.
  • White list: a fixed list of allowed items, here the origins permitted to be named in the allow header.
  • Endpoint: a specific address on a server that an API request can be sent to.

More from Automattic

View all

The newest disclosed reports for this program.

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.