Skip to content
Cache bugs Disclosed report Intermediate

woocommerce - prevent_caching() bug / bypass

WooCommerce's prevent_caching() function checks the raw request URI for cart, checkout and account paths, but WordPress canonical redirects accept extra characters such as a plus, minus or dot before the path. An attacker could therefore reach a dynamic page through a URL the cache helper does not recognise, so a caching layer may store and serve that page to other users.

b258ea62bf297b02afa9854 Follow

Originally disclosed on HackerOne

  • Paid in 18 days
  • Disclosed after 3 months

As guest visit the following links and look at the headers. Yup there are not caching headers in the response. (https://woocommerce.com/.cart/)[https://woocommerce.com/.cart/] (https://woocommerce.com/+cart/)[https://woocommerce.com/+cart/] (https://woocommerce.com/-cart/)[https://woocommerce.com/-cart/]

accept-ranges:bytes
age:0
content-encoding:gzip
content-type:text/html; charset=UTF-8
date:Mon, 19 Jun 2017 13:25:20 GMT
link:<https://woocommerce.com/wp-json/>; rel="https://api.w.org/"
link:<https://woocommerce.com/?p=18552>; rel=shortlink
server:nginx
set-cookie:woocommerce_items_in_cart=1; path=/
set-cookie:woocommerce_cart_hash=c670f81df612aa5e067bc7d1a33673da; path=/
set-cookie:wp_woocommerce_session_241766cd983ad3375c92fb5411ecef50=159536bf377374fa447e91a16437e611%7C%7C1498051468%7C%7C1498047868%7C%7Cbfae081ff1a2c69f9e4feda8128c7579; expires=Wed, 21-Jun-2017 13:24:28 GMT; Max-Age=172748; path=/
status:200
x-cache:pass
x-hacker:If you're reading this, you should visit automattic.com/jobs and apply to join the fun, mention this header.
x-pingback:https://woocommerce.com/xmlrpc.php
x-rq:vie1 87 24 3240

What happens?

Function prevent_caching() in the class-wc-cache-helper.php have the following line of code:

if ( stristr( trailingslashit( $_SERVER['REQUEST_URI'] ), $uri ) ) {

in order to protect the cart, my-account and checkout dynamic pages from being cached by caching wordpress plugins ( defines the caching constants ) or cloud proxies (sets no caching headers).

But from the wordpress itself we got the following e.g. pagename query param is passed trough sanitize_title_with_dashes and only thing left for successful exploitation/attack in case of woocomerce instance remains to defeat the redirect_canonical which is bypassed by -, + and . characters. This means that $_SERVER['REQUEST_URI'] will have this type of value /+my-account/ and needle will be /my-account/ and this will return false ofc. :)

This way in case of existing caching plugin set up to cache the wordpress pages even for logged in users, woocommerce store that allows guests to buy products or some another cases of web setups cache deception attack is ready to go.

Fix: Don't rely on the $_SERVER['REQUEST_URI'] param, but use it query object to get the pagename.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the caching check compares the raw request URI against a fixed path string, so any variant that WordPress still resolves to the same page (for example with a leading plus, minus or dot) fails the match and the page is treated as cacheable.

Impact

Where a caching plugin or proxy caches pages even for logged-in users, a cache deception attack could expose one user's cart or account page to others.

What the attacker needed

Guest access to the store; a caching layer that caches pages; cache configured to cache logged-in users

How it was found

  1. As a guest, request the cart page using a path with an extra character such as a plus, minus or dot before the name.
  2. Observe that the response lacks the no-cache headers that the normal cart path would set.
  3. The response sets WooCommerce cart cookies, so a caching layer may store the page.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Some pages, like a shopping cart, must never be stored by a caching system because they contain one person's data. This code tried to spot those pages by looking at the address the visitor typed, but it only matched the exact spelling. Adding a harmless extra character to the address made the check fail while the site still showed the cart page, so a cache could save it and hand it to someone else.

What is Cache bugs?

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.

More by b258ea62bf297b02afa9854

View all

8 more disclosed reports, best first.

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.