Skip to content
Cache bugs Write-up Intermediate

A web cache deception chained to a CSRF, the recipe

A web cache deception flaw allowed an attacker to force caching of a response containing a CSRF token, which could then be retrieved by the attacker. Chained with a CSRF attack, this let the attacker change the victim's delivery address.

Rachid.A Follow

Published on infosecwriteups.com

Recently, I received a bounty for a vulnerability discovered on an e-commerce site allowing the personal information — including the delivery address — of a user to be changed. Let’s talk about it!

Rachid.A, on infosecwriteups.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. 6 min read.

Context

This write-up covers a web cache deception (WCD) found on an e-commerce site, chained with a CSRF attack that let the researcher change a victim's delivery address. The target is a shopping application where a logged-in user can edit their personal details, including the delivery address. The application returns a CSRF token from a POST request, and that token is what the whole chain depends on.

The author had already covered how a web cache works in a previous article, DOS via cache poisoning, and refers readers there rather than repeating the basics.

Setup

The report does not describe any special accounts, roles or tool versions. The work started after the program sent a notification about new features being deployed, and the researcher spent a few minutes browsing the application. The only tooling mentioned is a second browser in Incognito mode, used to confirm that a cached response was served to a session that had not made the original request.

Finding it

While looking around the new features, the response to a POST request stood out:

HTTP
HTTP/2 200 OK
Accept-Ch: Sec-CH-UA,Sec-CH-UA-Mobile,Sec-CH-UA-Platform,Sec-CH-UA-Arch,Sec-CH-UA-Full-Version-List,Sec-CH-UA-Model,Sec-CH-Device-Memory
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Content-Type: text/html; charset=utf-8
Date: Tue, 24 Oct 2023 18:57:57 GMT
Referrer-Policy: no-referrer-when-downgrade
Vary: Accept-Encoding

{"token":"[redacted]"}

The body carries a CSRF token. The researcher's reasoning was that if this response could be cached, the token of any user who loads the crafted URL would be readable by the attacker, and any CSRF attack that the site's protections would otherwise block could then be mounted.

Exploitation

Step 1: force the response into the cache

The request verb was changed from POST to GET, and a static-file extension preceded by the character ; was appended to the path, followed by a cache buster:

Text
/;.js?cache-buster=zhero_

The ; before the extension is the trick the author highlights: it sometimes makes the server return 200 where a plain extension would return 404. The cache buster makes the cached entry retrievable only through the link containing that parameter value.

After this change, the response headers showed the value that marks the response as cacheable. To confirm, the researcher opened another browser in Incognito mode, loaded the crafted URL, and the CSRF token of the victim account came back from the cache.

source: somewhere on x From the original on infosecwriteups.com

Step 2: build the CSRF form

With the token readable after a single click from the victim, the next task was to find an action worth performing in the victim's name. Account takeover was the initial objective, and two features were checked:

  1. Password change: not possible, because the current password was required.
  2. Email address change: not possible, because the current password was also required (the author notes this is not always the case on other sites).

With account takeover excluded and no XSS found on the relevant vectors, the delivery address became the proof of concept, since altering it on an e-commerce site can cause real problems for an inattentive victim.

The HTML page below contains a form with the victim's fields and the stolen token in the token input, and submits itself on load:

HTML
<html>
    <form id="csrf" enctype="application/x-www-form-urlencoded" method="POST" action="https://www.nope.com/nope">
        <table>
            <tr><td>firstname</td><td><input type="text" value="zhero" name="firstname"></td></tr>
            <tr><td>lastname</td><td><input type="text" value="powned" name="lastname"></td></tr>
            <tr><td>address1</td><td><input type="text" value="8 rue test" name="address1"></td></tr>
            <tr><td>address2</td><td><input type="text" value="test" name="address2"></td></tr>
            <tr><td>postcode</td><td><input type="text" value="44000" name="postcode"></td></tr>
            <tr><td>city</td><td><input type="text" value="Nantes" name="city"></td></tr>
            <tr><td>id_country</td><td><input type="text" value="10" name="id_country"></td></tr>
            <tr><td>id_state</td><td><input type="text" value="124" name="id_state"></td></tr>
            <tr><td>phone_mobile</td><td><input type="text" value="2342342342" name="phone_mobile"></td></tr>
            <tr><td>alias</td><td><input type="text" value="sdfsdfsdfsdf" name="alias"></td></tr>
            <tr><td>token</td><td><input type="text" value="[redacted]" name="token"></td></tr>
            <tr><td>submitAddress</td><td><input type="text" value="" name="submitAddress"></td></tr>
        </table>
    </form>
    <script>
        document.getElementById('csrf').submit()
    </script>
</html>

The action in the report points at a placeholder host, not the real endpoint. The author notes that if any of these fields had been vulnerable to XSS, a stored XSS, and possibly an account takeover from there, would have been reachable.

Step 3: deliver the two clicks

The page can be tested locally or hosted, and the link to it is sent to the victim. When the victim opens it, the address is changed in one click. The full chain, cache deception included, needs two clicks from the victim: one on the crafted cache URL to plant the token, and one on the HTML page to submit it. The author calls that a lot relative to the impact, and describes how to reduce it to one click: a small web app that serves as the exploit, watches for the victim's click on the WCD link, pulls the token out of that same link with a simple regex, and puts the value into the POST request that fires the CSRF.

Root cause

The application returned a CSRF token in a response that the cache was willing to store, and the cache decided what to store from the URL rather than from the sensitivity of the content. Appending a static extension, here ;.js, made the request look like a static resource, so the cache stored the personalised response. The cache buster in the query string then gave the attacker a private key to the stored copy: only a request with the same parameter value gets that entry back.

On the CSRF side, once the token could be read by the attacker it stopped being a defence.

Impact

An attacker who gets a logged-in victim to click a crafted link can read that victim's CSRF token from the cache and then act in their name. In this case the action was changing the delivery address, which the author frames as a real problem on an e-commerce site. Account takeover was not achieved because the password change and email change features both required the current password. The report was accepted with a Medium severity, and the author argues that the same flaw leading to an account takeover would have justified a higher CVSS score, since only the impact matters.

source: somewhere on x From the original on infosecwriteups.com

Fix

The report does not say what the program changed.

Variants to test

  1. Try other static extensions after the path, such as .css, .png, .js, with and without a leading ;, and watch for a cacheable marker in the response headers. A positive result is a 200 whose body still contains the user's data.
  2. A positive result is another user's value coming back in Incognito mode from the same URL.
  3. Try the ; variant where a plain extension gives a 404. A positive result is a 200 with the sensitive body, since the author warns that even a cached 404 can still carry the user's information.
  4. Always add a unique cache buster and reuse the exact URL. A positive result is that the entry is only retrievable with that parameter value, which confirms the buster works as a key.

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

What happened, in plain words

A security researcher was looking at an online shop. When you log in to a shop, the shop remembers who you are, and it lets you change things like your name and your delivery address. The shop also uses a small secret code, called a CSRF token, to check that a change really came from you and not from someone else. The researcher found a way to make the shop's own caching system store that secret code, so that anyone who knew the right web address could read it. With the code in hand, an attacker could then change the victim's delivery address without the victim ever meaning to do it.

A bounty is a reward a company pays to someone who reports a security problem to them instead of using it for harm. This article walks through the whole story from the beginning, assuming you have never studied security before. You only need to know how to use a browser.

The pieces you need to understand first

Before the story makes sense, here are the ideas it relies on. Each one is explained from zero.

What a web cache is

When you visit a website, your browser asks a server for a page, and the server builds that page and sends it back. Building a page can take work. If thousands of people ask for the same picture or the same style sheet, the server would be doing the same work over and over. So most websites put a cache in front of the server: a storage layer that keeps a copy of a response and hands that copy to the next person who asks for the same thing. Think of a restaurant that keeps a pot of soup ready: the first customer waits while it is cooked, and everyone after gets a bowl straight away.

A cache only works if it can tell which requests are "the same thing". It looks at the web address (the URL) you asked for. If two people ask for the same URL, the second one may get the stored copy instead of a freshly built page.

What a cookie and a token are

When you log in, the server sends your browser a small piece of data called a cookie. Your browser sends that cookie back with every request you make to that site, and that is how the site knows it is you. A token is a similar idea: a short random-looking string that the server hands out and later checks. A CSRF token is a token used for one specific job, explained next.

What CSRF means

CSRF stands for Cross-Site Request Forgery. The idea: your browser automatically sends your cookies to a site, even when the request was triggered by a page on a completely different site. So if an attacker can trick your browser into sending a request to the shop, the shop will think the request came from you. To stop this, many sites require a secret CSRF token with every change. The attacker's page cannot know that token, so the request is rejected. The token is the lock; if the attacker can read the token, the lock is useless.

What web cache deception means

A web cache deception (WCD) is when an attacker tricks a cache into storing a response that was never meant to be stored, and then reads that stored copy. Normally a cache is only supposed to keep things that are the same for everybody, like images and style sheets. A page showing your private delivery address is different for every user, so it must never be cached. If the attacker can make the cache store it anyway, the attacker can come back later and read it.

The author had already written a separate article explaining how caches work, called DOS via cache poisoning, and points readers there rather than repeating the basics.

How the deception works in general

Not every response a server sends is meant to be cached. If a private page does get cached, the personal information of a logged-in user could be readable by anyone, for as long as the cache keeps it. That is clearly not what the site intended.

Most often, the things a site does allow to be cached are static resources: images, CSS and JavaScript files, fonts. These files do not change from user to user, so storing them saves work. The cache decides what to store by looking at the URL. If the URL ends in .css, .js or .png, the cache assumes it is a static file and stores it.

That assumption is the weakness. If an attacker takes a URL that returns private information and adds a static file extension to the end, the cache may treat it as a static file and store the private response.

Some examples of URLs shaped this way (the report calls this a non-exhaustive list):

Text
https://example.com/private_info.js?cachebuster=1
https://example.com/private_info/.css?cachebuster=1
https://example.com/private_info/;.png?cachebuster=1

Line by line:

  • The first line takes a private page and adds .js to the end, so the cache thinks it is a JavaScript file.
  • The second line adds /.css, a style sheet path, for the same reason.
  • The third line adds /;.png. The semicolon before the extension is a trick the author highlights: it sometimes makes the server return a normal 200 response where a plain extension would return a 404 error. A 404 means "not found".

The author also warns that caching a 404 page is not harmless. Sometimes the personal information of the logged-in user is still present on that error page, so a cached 404 can still leak data.

The cache buster

Each example above ends with ?cachebuster=1. That is a cache buster: a made-up URL parameter with a value the attacker chooses. A URL parameter is the part after the ? in a web address, made of a name and a value. The cache treats each different URL as a separate entry, so adding a unique parameter gives the attacker a private slot in the cache.

The author explains why this matters: the data cached when the victim clicks will only be accessible via the link containing that URL parameter. The cache buster therefore works like a key to the victim's information.

source: somewhere on x From the original on infosecwriteups.com

The real case

The program the researcher works with sent a notification saying new features had been deployed. The researcher decided to take a look, and after a few minutes of browsing, the response to a POST request caught their attention.

A POST request is one of the ways a browser talks to a server. When you fill in a form and press submit, your browser usually sends a POST request carrying the form's data. A GET request is the ordinary kind, used when you simply open a page or click a link. The difference matters later.

Here is the response that stood out:

HTTP
HTTP/2 200 OK
Accept-Ch: Sec-CH-UA,Sec-CH-UA-Mobile,Sec-CH-UA-Platform,Sec-CH-UA-Arch,Sec-CH-UA-Full-Version-List,Sec-CH-UA-Model,Sec-CH-Device-Memory
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Content-Type: text/html; charset=utf-8
Date: Tue, 24 Oct 2023 18:57:57 GMT
Referrer-Policy: no-referrer-when-downgrade
Vary: Accept-Encoding

{"token":"[redacted]"}

Line by line:

  • HTTP/2 200 OK is the status line. 200 means the request succeeded. HTTP/2 is the version of the protocol used to talk to the server.
  • The Accept-Ch line lists hints the server is willing to receive about the browser, such as its platform and version. These are informational.
  • The Alt-Svc line tells the browser about an alternative way to reach the same server. Also informational here.
  • Content-Type: text/html; charset=utf-8 says the body is HTML text encoded in UTF-8.
  • Date is when the response was produced.
  • Referrer-Policy controls how much of the previous page's address is shared when you follow a link.
  • Vary: Accept-Encoding tells caches that the stored copy depends on the encoding the browser accepts.
  • The blank line separates the headers from the body.
  • The body is {"token":"[redacted]"}: a small JSON object. JSON is a text format for structured data, made of names and values. Here the name is token and the value is a long random string.

That token is a CSRF token. The researcher's reasoning was simple: if this response could be made cacheable, then the token of any user who loads the crafted URL would be readable by the attacker. And with a readable token, any CSRF attack the site's protections would otherwise block could be carried out.

Step 1: force the response into the cache

The researcher changed the request verb from POST to GET, and added a static-file extension preceded by the character ;, followed by a cache buster:

Text
/;.js?cache-buster=zhero_

Line by line:

  • / is the path on the site.
  • ;.js is the trick. The .js makes the cache think this is a JavaScript file, and the ; before it is what the author highlights: it sometimes makes the server return 200 where a plain extension would return 404.
  • ?cache-buster=zhero_ is the cache buster. The value zhero_ is the researcher's own handle, chosen so the entry is unique to this URL.

Why change POST to GET? Because a cache is built to store responses to ordinary page requests, and a GET is the ordinary kind. A POST is a form submission, which a cache normally will not store. Switching to GET makes the request look like something the cache is willing to keep.

After this change, the response headers showed the value that marks the response as cacheable. To confirm, the researcher opened another browser in Incognito mode, loaded the crafted URL, and the CSRF token of the victim account came back from the cache.

Incognito mode is a browser window that does not share cookies or login state with your normal window. Opening the crafted URL there is a clean test: if the token still appears, it did not come from the researcher's own session, it came from the cache.

source: somewhere on x From the original on infosecwriteups.com

Step 2: build the CSRF form

With the token readable after a single click from the victim, the next task was to find an action worth performing in the victim's name. Account takeover was the initial objective. Account takeover (ATO) means an attacker gains full control of someone else's account, for example by changing the password or the email address so the real owner can no longer log in. Two features were checked:

  1. Password change: not possible, because the current password was required.
  2. Email address change: not possible, because the current password was also required. The author notes this is not always the case on other sites.

With account takeover excluded, and no XSS found on the relevant vectors, the delivery address became the proof of concept. XSS stands for cross-site scripting: a way to make a site run code the attacker supplied. A proof of concept (PoC) is a small demonstration that a problem is real. On an e-commerce site, changing the delivery address can cause real problems for a victim who is not paying attention.

The HTML page below contains a form with the victim's fields and the stolen token in the token input, and it submits itself as soon as it loads:

HTML
<html>
    <form id="csrf" enctype="application/x-www-form-urlencoded" method="POST" action="https://www.nope.com/nope">
        <table>
            <tr><td>firstname</td><td><input type="text" value="zhero" name="firstname"></td></tr>
            <tr><td>lastname</td><td><input type="text" value="powned" name="lastname"></td></tr>
            <tr><td>address1</td><td><input type="text" value="8 rue test" name="address1"></td></tr>
            <tr><td>address2</td><td><input type="text" value="test" name="address2"></td></tr>
            <tr><td>postcode</td><td><input type="text" value="44000" name="postcode"></td></tr>
            <tr><td>city</td><td><input type="text" value="Nantes" name="city"></td></tr>
            <tr><td>id_country</td><td><input type="text" value="10" name="id_country"></td></tr>
            <tr><td>id_state</td><td><input type="text" value="124" name="id_state"></td></tr>
            <tr><td>phone_mobile</td><td><input type="text" value="2342342342" name="phone_mobile"></td></tr>
            <tr><td>alias</td><td><input type="text" value="sdfsdfsdfsdf" name="alias"></td></tr>
            <tr><td>token</td><td><input type="text" value="[redacted]" name="token"></td></tr>
            <tr><td>submitAddress</td><td><input type="text" value="" name="submitAddress"></td></tr>
        </table>
    </form>
    <script>
        document.getElementById('csrf').submit()
    </script>
</html>

Line by line:

  • <html> opens the page.
  • <form id="csrf" ...> starts a form. The id is a name used later by the script. enctype="application/x-www-form-urlencoded" is the standard way form data is encoded when sent. method="POST" says the form is submitted as a POST request. action="https://www.nope.com/nope" is where the form is sent. The report uses a placeholder host here, not the real endpoint.
  • Each <tr> is a table row, and each row holds a field name and an <input>. An <input> is a box in a form. type="text" makes it a text box, value is what is already filled in, and name is the label the server will see.
  • The fields are the victim's details: firstname, lastname, address1, address2, postcode, city, id_country, id_state, phone_mobile, alias, and submitAddress. The values are the attacker's chosen replacements, such as zhero, powned, 8 rue test, 44000, Nantes.
  • The token field carries the stolen CSRF token, [redacted]. This is the whole point: the form includes the secret so the shop will accept the change.
  • </form> closes the form.
  • <script> starts a small piece of JavaScript, the language browsers run. document.getElementById('csrf').submit() finds the form by its id and submits it immediately. The victim does not have to press anything.
  • </script> and </html> close the page.

The author notes that if any of these fields had been vulnerable to XSS, a stored XSS, and possibly an account takeover from there, would have been reachable. Stored XSS means the malicious code is saved on the site and runs for anyone who views the affected page.

Step 3: deliver the two clicks

The page can be tested locally or hosted somewhere, and the link to it is sent to the victim. When the victim opens it, the address is changed in one click. The full chain, cache deception included, needs two clicks from the victim: one on the crafted cache URL to plant the token, and one on the HTML page to submit it.

The author calls that a lot relative to the impact, and describes how to reduce it to one click: a small web app that serves as the exploit, watches for the victim's click on the WCD link, pulls the token out of that same link with a simple regex, and puts the value into the POST request that fires the CSRF. A regex is a pattern used to find a piece of text inside a larger text, here the token inside the cached response.

Why it worked

The application returned a CSRF token in a response that the cache was willing to store, and the cache decided what to store from the URL rather than from how sensitive the content was. Appending a static extension, here ;.js, made the request look like a static resource, so the cache stored the personalised response. The ; before it is what the author highlights: it sometimes makes the server return 200 where a plain extension would return 404. The cache buster in the query string then gave the attacker a private key to the stored copy: only a request with the same parameter value gets that entry back.

On the CSRF side, once the token could be read by the attacker it stopped being a defence.

What the impact was

An attacker who gets a logged-in victim to click a crafted link can read that victim's CSRF token from the cache and then act in their name. In this case the action was changing the delivery address, which the author frames as a real problem on an e-commerce site. Account takeover was not achieved because the password change and email change features both required the current password. The report was accepted with a Medium severity, and the author argues that the same flaw leading to an account takeover would have justified a higher CVSS score, since only the impact matters.

Severity is a rough rating of how bad a problem is. CVSS is a standard scoring system for that rating. The author's point is that the score should follow what an attacker can actually do, not how clever the trick was.

source: somewhere on x From the original on infosecwriteups.com

How to fix it

The report does not say what the program changed. The report does not say what the program changed or how the issue was fixed.

Things to try yourself

If you want to look for the same kind of problem on a site you are allowed to test, these are the variants the write-up suggests. A variant is a small change to the same idea, to see whether it works elsewhere.

  1. Try other static extensions after the path, such as .css, .png, .js, with and without a leading ;, and watch for a cacheable marker in the response headers. A positive result is a 200 whose body still contains the user's data.
  2. An API is the part of a site that other software talks to, returning data rather than a full page. A positive result is another user's value coming back in Incognito mode from the same URL.
  3. Try the ; variant where a plain extension gives a 404. A positive result is a 200 with the sensitive body, since the author warns that even a cached 404 can still carry the user's information.
  4. Always add a unique cache buster and reuse the exact URL. A positive result is that the entry is only retrievable with that parameter value, which confirms the buster works as a key.

Glossary

  • Account takeover (ATO): when an attacker gains full control of someone else's account, for example by changing the password or email so the real owner cannot log in.
  • API: the part of a site that other software talks to, returning data rather than a full page.
  • Bounty: a reward a company pays to someone who reports a security problem to them instead of using it for harm.
  • Cache: a storage layer in front of a server that keeps copies of responses and hands them to later visitors, to save work.
  • Cache buster: a made-up URL parameter with a value the attacker chooses, so the cached entry is unique to that URL and works like a key.
  • Cookie: a small piece of data a site stores in your browser and receives back with every request, used to remember who you are.
  • CSRF (Cross-Site Request Forgery): tricking a victim's browser into sending a request to a site where they are logged in, so the site thinks the request came from the victim.
  • CSRF token: a secret string a site requires with a change, so that a request forged by another site is rejected.
  • CVSS: a standard scoring system for rating how bad a security problem is.
  • GET request: the ordinary kind of request used when you open a page or click a link.
  • HTML: the language used to write web pages.
  • JSON: a text format for structured data, made of names and values.
  • POST request: the kind of request a browser sends when you submit a form, carrying the form's data.
  • Proof of concept (PoC): a small demonstration that a problem is real.
  • Regex: a pattern used to find a piece of text inside a larger text.
  • Severity: a rough rating of how bad a security problem is.
  • Static resource: a file that is the same for every visitor, such as an image, style sheet, script or font, and which caches are happy to store.
  • Stored XSS: cross-site scripting where the malicious code is saved on the site and runs for anyone who views the affected page.
  • Token: a short random-looking string a server hands out and later checks.
  • URL parameter: the part of a web address after the ?, made of a name and a value.
  • Variant: a small change to the same idea, tried to see whether it works elsewhere.
  • Web cache deception (WCD): tricking a cache into storing a response that was never meant to be stored, then reading that stored copy.
  • XSS (cross-site scripting): a way to make a site run code the attacker supplied.

More by Rachid.A

View all

1 more disclosed report, 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.