Skip to content
XSS Write-up Intermediate

How Private Cache Can Lead to Mass Account Takeover – pentest case

A search parameter was sanitised on the first request but a broken private cache stored the unsanitised response, so repeating the same request returned executable JavaScript. Because the response body also contained session cookies, an attacker could steal cookies and, by poisoning search suggestions, achieve mass account takeover.

Mateusz Kowalczyk Follow

Published on research.securitum.com

In many situations, minor vulnerabilities might seem like small fish in the vast ocean of cybersecurity threats. They’re often marked as low severity and thus, overlooked by developers who assume that the conditions for their exploitation are too complicated to be met.

miwn, on research.securitum.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. 5 min read.

Context

This is a pentest case study about how a set of individually minor issues in a web application combined into a Mass Account Takeover. The application under test is not named in the write-up, and the host is redacted throughout. The relevant feature is a search function: the application takes a SEARCH parameter and reflects its value back in the response body, and it also offers phrase suggestions in the search engine, similar to how a search engine proposes the next words as you type.

The write-up frames three concepts before getting into the finding:

  • Vulnerability chain: several connected vulnerabilities that culminate in a serious one. A reflected XSS is the example given: on its own it is often treated as medium severity, but combined with cookies that lack the appropriate security flags it can escalate to an account takeover.
  • Cache mechanism: developers store data closer to the user so it does not have to be loaded from the database on every request, which saves resources when thousands of users are active at once. The cache can be set individually or shared among users.
  • Application features: functionality added to improve the user experience, such as search suggestions.

Setup

The write-up does not describe accounts, roles, tools or product versions. What it does describe is the testing methodology: during the application audit, the testers identified application parameters and monitored their behaviour within the application environment. For a parameter such as SEARCH, the natural checks are SQL injection, XSS, server-side request forgery (SSRF), server-side template injection (SSTI) and so on. The work started with a basic check for the reflected value.

The testing is described as black box: auditors do not know which parameters the application processes, so the exercise is about learning how the application works and how a hacker would behave in a real attack scenario.

Finding it

The first step was to send a TEST value for the SEARCH parameter and see whether it came back.

HTTP
GET /?SEARCH=TEST HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

The response was a 200 with the value reflected in the body:

HTTP
HTTP/2 200 OK
…
[APPLICATION SOURCE CODE]
TEST
[APPLICATION SOURCE CODE]
…

A reflected value is important information for the auditor: it shows the parameter is processed and reflected. The next step was a more advanced payload:

Text
><script>alert(document.domain)</script>

Sent in the same way:

HTTP
GET /?SEARCH=><script>alert(document.domain)</script> HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

The response came back with the payload HTML-entity encoded:

HTTP
HTTP/2 200 OK
…
[SOURCE CODE OF APPLICATION]
\u003e\u003cscript\u003ealert(document.domain)\u003c/script\u003e
[SOURCE CODE OF APPLICATION]
…

Everything seemed okay. The SEARCH parameter appeared to be sanitised, so the auditor moved on to another parameter. Then the story took an unexpected turn: what happens if the exact same request is repeated?

Exploitation

Step 1: repeat the identical request

The same request, with the same payload, was sent again:

HTTP
GET /?SEARCH=><script>alert(document.domain)</script> HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

This time the response body contained the payload unencoded:

HTTP
HTTP/2 200 OK
…
[APPLICATION SOURCE CODE]
><script>alert(document.domain)</script>
[SOURCE CODE OF APPLICATION]
…

The first response was correctly sanitised, but the second one allowed arbitrary JavaScript execution. The cause is a broken cache mechanism. In the tested application the cache worked individually for each user, so it was not possible to poison the cache for all users. That raises the obvious question: how is this exploitable at all?

Step 2: understand what the cache bypass gives you

To steal sensitive user data such as session cookies, two conditions must be met: the XSS must exist in the application, and the cookies must not be set with HttpOnly. In the tested application neither condition was met on its own, because the parameters were sanitised and the cookies had the appropriate flags set. Two things then went wrong:

  1. The cache mechanism allowed bypassing the sanitisation if at least two of the same requests were sent to the application.
  2. The response body contained an object with session cookies.

Step 3: from one victim to many

In the single-victim scenario it is necessary to target potential victims and convince them to click a link twice or visit a malicious website. Awareness of this type of attack is common, so tricking someone into that scenario can be difficult.

The application also has a feature that suggests phrases in the search engine. By poisoning the search engine with malicious suggestions, mass XSS execution may be possible, leading to a Mass Account Takeover. The two separate issues, the cache mechanism allowing the bypass of sanitisation and the response body containing an object with session cookies, culminated in a serious problem.

Root cause

The cause is a broken cache mechanism: the first response was sanitised, but a repeated identical request returned the payload unencoded. The write-up does not explain how the cache is implemented. Because the cache was per user, an attacker could not poison it for everyone directly, but the same broken behaviour still let any single user's own repeated request bypass the filter.

The existing defences did not stop the chain: parameters were sanitised and the cookies had appropriate flags set, but the response body contained an object with session cookies. The write-up does not go into the code that implements the cache, so the exact implementation flaw is not shown.

Impact

Repeating the same request twice allowed arbitrary JavaScript execution, and the response body contained an object with session cookies. In the single-victim case this means convincing a target to click a link twice or visit a malicious website. In the mass case, poisoning the search engine with malicious suggestions could lead to mass XSS execution and a Mass Account Takeover. The write-up hedges the mass scenario with "may be possible" and "could be possible"; it does not provide a count of affected users or a demonstration against real accounts.

Fix

The write-up stresses that minor vulnerabilities should not be underestimated, and that prevention, thorough testing and proactive mitigation strategies are essential.

Variants to test

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

What happened, in plain words

A security tester was hired to look at a website. The website had a search box, the kind where you type a word and it shows you results, and also suggests phrases as you type, a bit like a search engine proposing the next words. On its own, the site looked careful: when the tester typed something dangerous into the search box, the site cleaned it up before showing it back. The cookies, the little files a site uses to remember who you are, were also protected properly.

But the tester noticed something odd. When the exact same request was sent a second time, the site showed the dangerous text back without cleaning it. The reason was a broken cache. A cache is a shortcut: instead of doing the same work again, the site keeps a copy of an earlier answer and hands that copy back. The first response was cleaned, but the repeated request returned the dangerous text without cleaning.

That alone would be a small problem, because the cache was private to each user. But the site's answers also contained an object holding the user's session cookies, the values that prove who you are. Put those two things together and a repeated request could run JavaScript in the site's own pages, while the response body contained an object with session cookies. And because the site suggests search phrases, poisoning the search engine with malicious suggestions may have made mass XSS execution possible, leading to a Mass Account Takeover.

The three ideas you need first

Before the finding, the write-up introduces three concepts. They are worth understanding because the whole story depends on them.

Vulnerability chain

A vulnerability is a weakness in a website that someone could abuse. A vulnerability chain is several weaknesses that, joined together, become much more serious than any one of them alone. Think of dominoes: each tile is small, but knock the first one and the whole row falls.

The example given is reflected cross-site scripting, usually shortened to XSS. In a reflected XSS, whatever you type into a box is sent back to you in the page, and if the site does not clean it, your text can be treated as code by the browser. On its own, reflected XSS is often rated medium severity, meaning it is a real problem but not the worst kind. Combine it with cookies that lack the right protection flags, and it can grow into an account takeover, where an attacker ends up logged in as the victim.

Cache mechanism

A cache is a copy kept close at hand so the site does not have to fetch the same thing from its database every time. Imagine a librarian who, instead of walking to the shelves for a popular book, keeps a copy behind the desk. It saves a lot of walking when thousands of people ask at once. The write-up notes that a cache can be set individually, one copy per user, or shared among users, one copy for everybody.

Application features

Features are the extras a site adds to make life easier. The example given is search suggestions: you type a word and the site offers likely next words, such as "the most interesting..." or "the most fascinating...". These suggestions are a feature, and features can become part of an attack surface, meaning a place where an attacker can try things.

How the tester worked

The write-up does not describe accounts, roles, tools or product versions. What it does describe is the method. During the audit, the testers identified the parameters the application accepts and watched how those parameters behaved inside the application.

A parameter is a named value you attach to a request, usually after a question mark in the address. If you have ever seen a web address ending in ?q=cats, then q is the parameter and cats is its value. For a parameter such as SEARCH, the natural checks are the classic web attacks: SQL injection, XSS, server-side request forgery (SSRF), server-side template injection (SSTI) and so on. The work started with the simplest possible check: does the value come back?

The testing is described as black box. In black box testing the auditor has no inside knowledge of the code and does not know in advance which parameters the application processes. The exercise is about learning how the application works, the way a real attacker would have to.

Finding it

Step 1: send a harmless value

The first step was to send a TEST value for the SEARCH parameter and see whether it came back.

HTTP
GET /?SEARCH=TEST HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

Line by line:

  • GET /?SEARCH=TEST HTTP/2 is the request line. GET is the method, the verb that says "give me this page". / is the path, here the site's front page. ?SEARCH=TEST is the parameter and its value. HTTP/2 is the version of the language the browser and server use to talk.
  • Host: […REDACTED-HOST…] names the website being asked. The actual name is hidden in the write-up.
  • User-Agent: […REDACTED…] normally says which browser and system is asking. It is hidden here too.
  • … means more header lines followed that the write-up does not show.

The response was a 200 with the value reflected in the body:

HTTP
HTTP/2 200 OK
…
[APPLICATION SOURCE CODE]
TEST
[APPLICATION SOURCE CODE]
…

Line by line:

  • HTTP/2 200 OK is the status line. 200 is the code for "here is your page".
  • … stands for response headers the write-up leaves out.
  • [APPLICATION SOURCE CODE] is a placeholder for the site's own HTML, the markup that makes up the page.
  • TEST is our value, sitting in the middle of that markup.
  • The second [APPLICATION SOURCE CODE] is more of the page after our value.

Why this step matters: a reflected value tells the auditor the parameter is actually processed and placed into the page. In a black box test that is valuable information, because it shows where the application listens to input.

Step 2: send something dangerous

The next step was a more advanced payload. A payload is the piece of input an attacker sends to try to trigger a weakness.

Text
><script>alert(document.domain)</script>

What this payload is made of:

  • > closes whatever HTML tag was open just before our value, so the browser stops treating our text as part of that tag.
  • <script> opens a script element. Anything inside it is treated as JavaScript, the programming language browsers run.
  • alert(document.domain) is a tiny script that pops up a box showing the site's domain, the address part that identifies the site. It is the standard harmless proof that script is running.
  • </script> closes the script element.

Sent in the same way:

HTTP
GET /?SEARCH=><script>alert(document.domain)</script> HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

Line by line:

  • The request line is the same as before, except the value after SEARCH= is now the payload.
  • The Host and User-Agent lines are unchanged, still redacted.
  • … again stands for headers not shown.

The response came back with the payload HTML-entity encoded:

HTTP
HTTP/2 200 OK
…
[SOURCE CODE OF APPLICATION]
\u003e\u003cscript\u003ealert(document.domain)\u003c/script\u003e
[SOURCE CODE OF APPLICATION]
…

Line by line:

  • HTTP/2 200 OK again means the page was served normally.
  • [SOURCE CODE OF APPLICATION] is the site's markup around our value.
  • The long string is our payload with its special characters replaced. \u003e is the encoded form of >, and \u003c is the encoded form of <. Encoding like this turns characters that the browser would treat as markup into plain text, so the browser shows them instead of acting on them.
  • The closing [SOURCE CODE OF APPLICATION] is the rest of the page.

Why this step matters: encoding is the site's defence. If < and > arrive as text, the browser never sees a real script tag, so nothing runs. Everything seemed okay. The SEARCH parameter appeared to be sanitised, meaning cleaned of dangerous characters, so the auditor moved on to another parameter.

Step 3: the unexpected turn

Then the story took an unexpected turn. What happens if the exact same request is repeated? The same request, with the same payload, was sent again:

HTTP
GET /?SEARCH=><script>alert(document.domain)</script> HTTP/2
Host: […REDACTED-HOST…]
User-Agent: […REDACTED…]
…

Line by line:

  • This is byte for byte the request from the previous step. Nothing changed: same path, same parameter, same payload, same headers.
  • The point of repeating it is to see whether the site gives the same answer twice. A well-behaved site should.

This time the response body contained the payload unencoded:

HTTP
HTTP/2 200 OK
…
[APPLICATION SOURCE CODE]
><script>alert(document.domain)</script>
[SOURCE CODE OF APPLICATION]
…

Line by line:

  • HTTP/2 200 OK is the same normal status.
  • [APPLICATION SOURCE CODE] is the page markup before our value.
  • ><script>alert(document.domain)</script> is our payload exactly as we sent it, with real angle brackets. The browser now sees a genuine script tag and runs the script.
  • [SOURCE CODE OF APPLICATION] is the rest of the page.

Why this matters: the first response was correctly sanitised, but the second one allowed arbitrary JavaScript execution. Arbitrary here means the attacker can run any script they like, not just the harmless alert. The cause is a broken cache mechanism. In the tested application the cache worked individually for each user, so it was not possible to poison the cache for all users. Poisoning a cache means planting a bad copy that other people will later be served. That raises the obvious question: if the bad copy only ever reaches the person who planted it, how is this exploitable at all?

Exploitation

Step 1: what the repeat actually gives you

To steal sensitive user data such as session cookies, two conditions must be met. First, the XSS must exist in the application. Second, the cookies must not be set with HttpOnly. HttpOnly is a flag a site can put on a cookie that tells the browser: never let JavaScript read this cookie. It is a seatbelt for cookies.

In the tested application neither condition was met on its own, because the parameters were sanitised and the cookies had the appropriate flags set. Two things then went wrong:

  1. The cache mechanism allowed bypassing the sanitisation if at least two of the same requests were sent to the application.
  2. The response body contained an object with session cookies.

A session cookie is the value that proves to the site that you are logged in. If someone else gets it, they can often act as you. An object here means a structured bundle of data inside the page, not just a single value.

Step 2: from one victim to many

In the single-victim scenario it is necessary to target potential victims and convince them to click a link twice or visit a malicious website. Awareness of this type of attack is common, so tricking someone into that scenario can be difficult. People have learned not to click strange links, and asking someone to click the same link twice is even stranger.

The application also has a feature that suggests phrases in the search engine. By poisoning the search engine with malicious suggestions, mass XSS execution may be possible, leading to a Mass Account Takeover. In other words, if the attacker can get the payload into the pool of suggested phrases, every user who sees that suggestion may run the script without clicking anything unusual. The two separate issues, the cache mechanism allowing the bypass of sanitisation and the response body containing an object with session cookies, culminated in a serious problem.

Root cause

The mistake is in the cache mechanism. The first response was sanitised, but a repeated identical request returned the payload unencoded. Because the cache was per user, an attacker could not poison it for everyone directly, but the same broken behaviour still let any single user's own repeated request bypass the filter.

The existing defences did not stop the chain. Parameters were sanitised and the cookies had appropriate flags set, but the response body contained an object with session cookies. The write-up does not go into the code that implements the cache, so the exact implementation flaw is not shown.

Impact

Repeating the same request twice allowed arbitrary JavaScript execution, and the response body contained an object with session cookies. Origin here means the site's own address and security boundary: script running there is trusted by the site. In the single-victim case this means convincing a target to click a link twice or visit a malicious website. In the mass case, poisoning the search engine with malicious suggestions could lead to mass XSS execution and a Mass Account Takeover. The write-up hedges the mass scenario with "may be possible" and "could be possible"; it does not provide a count of affected users or a demonstration against real accounts.

Fix

The write-up closes by stressing that minor vulnerabilities should not be underestimated, and that prevention, thorough testing and proactive mitigation strategies are essential.

Variants to test

Glossary

  • Account takeover: a situation where an attacker gains control of someone else's account, for example by obtaining their session.
  • Application source code: the HTML and other markup that makes up a web page, as sent by the server.
  • Arbitrary JavaScript execution: the ability of an attacker to run any script they choose in a page, not just a harmless test.
  • Black box testing: testing a system with no knowledge of its internals, learning its behaviour only from the outside.
  • Cache: a stored copy of an earlier answer, kept so the same work does not have to be done again.
  • Cache poisoning: planting a bad copy in a cache so that other users are later served it.
  • Context (reflection context): the place in the page where your input ends up, such as inside a tag, an attribute or a script block.
  • Cookie: a small piece of data a site stores in your browser and sends back with later requests, often used to remember who you are.
  • Cross-site scripting (XSS): a weakness where input from a user is treated as code by the browser, letting an attacker run script in the site's pages.
  • Domain: the part of a web address that identifies the site, such as the name before the first slash.
  • Encoding (HTML-entity encoding): replacing characters such as < and > with safe text forms so the browser displays them instead of acting on them.
  • Feature: an extra function a site offers to improve the user experience, such as search suggestions.
  • GET: the HTTP method used to ask a server for a page or resource.
  • Header: a line in a request or response carrying extra information, such as the host name or the browser type.
  • Host: the header that names the website being requested.
  • HTML: the markup language that describes the structure of a web page.
  • HTTP/2: a version of the protocol browsers and servers use to exchange requests and responses.
  • HttpOnly: a cookie flag that stops JavaScript from reading that cookie.
  • JavaScript: the programming language that browsers run inside web pages.
  • Mass Account Takeover: an account takeover affecting many users at once rather than a single target.
  • Object (in a response body): a structured bundle of data embedded in a page, as opposed to a single plain value.
  • Origin: the combination of scheme, host and port that defines a site's security boundary; script running in a page belongs to that origin.
  • Parameter: a named value attached to a request, usually after a question mark in the address.
  • Payload: the input an attacker sends in an attempt to trigger a weakness.
  • Reflected value: input that the server sends back in its response.
  • Request: the message a browser sends to a server asking for something.
  • Response: the message a server sends back, including a status code, headers and a body.
  • Response body: the main content of a response, such as the page itself.
  • Sanitisation: cleaning input so that dangerous characters cannot be interpreted as code.
  • Script tag: the HTML element, <script>, whose contents the browser runs as code.
  • Server-side request forgery (SSRF): a weakness where an attacker can make the server send requests to places the attacker chooses.
  • Server-side template injection (SSTI): a weakness where attacker input is evaluated as part of a template on the server.
  • Session cookie: the cookie value that proves you are logged in; stealing it often lets an attacker act as you.
  • Severity: a rating of how serious a weakness is, often low, medium or high.
  • SQL injection: a weakness where attacker input changes the database queries a site runs.
  • Status code: the number at the start of a response saying how the request went, such as 200 for success.
  • Token: a value that stands in for identity or permission, similar in role to a session cookie.
  • User-Agent: the header that normally identifies the browser and system making a request.
  • Vulnerability: a weakness in a system that someone could abuse.
  • Vulnerability chain: several weaknesses that, combined, produce a more serious attack than any one alone.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.