Self XSS to persistent XSS on login portal
The login page reflected the user's first name without sanitisation, allowing a stored self-XSS. By chaining this with a login CSRF flaw (reusing a CSRF token across sessions), an attacker could force a victim to log into the attacker's account and then execute the stored script when the victim visited the login page.
Published on medium.com
About 2 months ago, I discovered a persistent self-XSS on a login portal. Most of programs do not accept self-XSS report, but I managed to escalate this to persistent XSS on login page by chaining with Login CSRF and reported to the program as valid vulnerability.
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
This is a write-up of a bug found on a private program, referred to throughout as redacted.com. The target was an account portal where a logged-in user could change settings on their account, including their first name and last name. The same name was later reflected on the login page as a greeting. The chain that turned a self-XSS into a persistent XSS on the login page relied on a login CSRF, and the report was accepted as a valid vulnerability with a reward of $500 plus a $150 bonus.

Setup
The researcher worked against a private program, so the real hostname is not given. The tools used were a browser (including CTRL+U to view page source), Burp Suite to inspect the login request, and viewdns.org to look up IP history. The precondition for the whole chain is an account on the portal whose first name or last name can be set to attacker-controlled HTML.
Finding it
The researcher spent time tampering with every parameter on the account settings page. The result was that there was no validation of first name and last name on the backend, so a name could be changed to something like <em>John</em>. However, <script> tags and common XSS payloads were not allowed, because Cloudflare sat between the frontend and the backend, and the reflected name on the account page was filtered as well: < was escaped to <.
Because of this hardening the researcher stopped looking at the account portal. A few days later, while on the login page, they noticed something strange before typing credentials: the page greeted them with the name they had changed last time, John, but the <em> tag was missing from the visible output. Pressing CTRL+U to view the source showed the HTML tag enclosing the name, unfiltered.
Exploitation
Step 1: bypass the WAF by reaching the origin
The researcher researched how to bypass the Cloudflare WAF. The core idea, as described, is to look for the origin IP of the server. The simplest way given is to look for IP history on viewdns.org: if the website was initially set up without Cloudflare, an origin IP would be logged in the Internet history.
An origin IP was found recorded on viewdns.org. Accessing the website from its origin IP and changing the name to the following payload got it past to the backend with no Cloudflare WAF involved:
<script>alert(\"Are you hungry?\")</script>
As expected, the alert box prompted when the login page was visited. This confirmed a self-XSS on the login page.
Step 2: understand how the payload is stored and reflected
The report describes the storage and reflection behaviour as follows:
- After login, if the user ticks the Remember me box, the session is saved in a cookie named
rememberme, with an expiration time set to one year. - If a user visits the login page again, even without logging out first, they are greeted with the first name reflected on the login page.
The consequence drawn is that if a login CSRF could be found, other users could be forced to log into the attacker's account, and on their next visit to the login page the attacker's XSS payload would execute.
Step 3: test the login CSRF token
Burp Suite was used to inspect the login request. As expected, a CSRF token was sent along with the credentials during the login request. Removing that token and re-sending the request failed.
Step 4: reuse a token from another session
The researcher then tried what the report calls a "poor man CSRF". The reasoning given is that an anti-CSRF system normally ties the CSRF token to something that identifies the person performing the action. If the CSRF token is not tied to the user's session, an attacker can grab a valid CSRF token from the website and reuse it on the victim.
Copying the CSRF token from a different browser session and reusing it resulted in a successful login to the account. This was the way to force the XSS on a user's login page.
Step 5: proof of concept
The following proof-of-concept code was used to exploit the chain:
<?php $html = file_get_contents('https://redacted.com/login'); preg_match('/name\=\”CSRF_TOKEN\” value\=\”(.*?)\”\', $html, $match); if( count ($match) ){ $token = $match[1]; echo '
<form name=”loginForm” target=”_blank”>
<!-—
form that contains my credentials + grabbed CSRF token
-->
</form>
<script>
window.forms.loginForm.submit();
</script>
'; }?>
The script fetches the login page, extracts the CSRF token with a regular expression, and prints a form containing the attacker's credentials plus the grabbed token, followed by a script that submits the form automatically. When a user visits the attacker's page, they are forced to log into the attacker's account, and on their next visit to the login page they are greeted with the attacker's XSS payload.
Root cause
The backend did not validate the first name and last name fields, so HTML could be stored in them. The account page escaped < to <, and Cloudflare blocked common payloads on the normal path, but the login page reflected the stored name without escaping it. The login CSRF token was not tied to the user's session, so a token obtained from one session could be reused in another. Together these allowed an attacker to store a script in their own profile and have it execute in a victim's browser after forcing the victim into the attacker's session.
Impact
An attacker could force a victim who visits the attacker's page to log into the attacker's account, and on the victim's next visit to the login page the stored payload would execute in the victim's browser.
Fix
A fix was deployed on 17 March 2020, after the reward was paid on 14 March 2020. The report does not describe what the fix changed.
Variants to test
- Look for stored HTML in profile fields that is escaped on one page but reflected unescaped on another, such as a login greeting. A positive result is a tag appearing in the page source where the visible output does not show it.
- Check whether the login CSRF token is tied to the session by copying a token from one browser session and reusing it in another. A positive result is a successful login with the reused token.
- Check IP history services such as viewdns.org for origin IPs of hosts behind a WAF. A positive result is the site responding on the origin IP and accepting payloads the WAF would block.
- Test whether the Remember me cookie keeps a session alive long enough for a stored payload to be reflected on a later visit to the login page. A positive result is the greeting appearing after the cookie is set and the user returns to the login page.
Timeline
| Date | Event |
|---|---|
| Feb 10, 2020 | Report sent |
| Feb 11, 2020 | Triage with Medium severity |
| Mar 14, 2020 | Reward $500 + $150 (bonus) |
| Mar 17, 2020 | Fix deployed |
What happened, in plain words
A security researcher found a way to make a website store a small piece of code in a user's profile and then run that code in someone else's browser. On its own, the first bug was harmless: it only let you attack yourself, which most bug bounty programs ignore. By combining it with a second, separate weakness in the login form, the researcher turned it into an attack that could hit other people. The program accepted the report and paid $500 plus a $150 bonus.
The site is a private program, so the real name is hidden and the report calls it redacted.com. The target was an account portal: a page where a logged-in user can change settings on their account, including their first name and last name. The same name was later shown on the login page as a greeting. The chain that turned a self-XSS into a persistent XSS on the login page relied on a login CSRF.

Before going further, a few words on the vocabulary, because the rest of the article uses it constantly.
- XSS (cross-site scripting) is when a website takes something a user typed and puts it into a page in a way that the browser treats as code instead of text. If the site stores your name and later prints it into the page without cleaning it, and your name contains a
<script>tag, the browser may run that script. A script running in a page can, in principle, do things on behalf of whoever is viewing the page. - Self-XSS is the harmless version: the only person who can trigger the script is the person who typed it. It is like writing a prank note and hiding it in your own desk drawer. Nobody else is affected, which is why most programs do not pay for it.
- Persistent (stored) XSS is the dangerous version: the malicious text is saved on the server and shown to other people later. The prank note is now in a shared noticeboard that everyone walks past.
- CSRF (cross-site request forgery) is when an attacker's page makes a visitor's browser send a request to another site, without the visitor meaning to. The browser attaches whatever the visitor is logged in with, so the other site thinks the request came from the visitor.
- Login CSRF is a specific flavour: the attacker's page quietly logs the visitor into the attacker's account instead of their own. The visitor ends up inside someone else's account without noticing.
- A cookie is a small piece of text a website asks the browser to keep and send back on every later visit. It is how a site remembers that you are logged in, like a wristband at an event.
- A CSRF token is a random value a site puts into a form so that it can tell a genuine submission from a forged one. The site checks the value when the form is sent. If an attacker cannot guess or obtain the value, they cannot forge the request.
- A WAF (web application firewall) is a filter that sits in front of a website and blocks requests that look malicious, such as ones containing
<script>. Cloudflare is a well-known provider of this kind of service. - An origin IP is the real address of the server behind such a filter. If you can reach the server directly, you skip the filter entirely, like finding the staff entrance at the back of a building.
- Burp Suite is a tool that lets you watch and edit the requests your browser sends to a website. It is like a transparent pipe you can open and change what flows through it.
Setup
The researcher worked against a private program, so the real hostname is not given. The tools used were a browser (including CTRL+U to view page source), Burp Suite to inspect the login request, and viewdns.org to look up IP history. The precondition for the whole chain is an account on the portal whose first name or last name can be set to attacker-controlled HTML.
CTRL+U is the browser shortcut that shows the raw HTML the server sent, as opposed to the page as drawn on screen. The two can differ: the browser may hide or strip something visually while the underlying source still contains it. That difference is exactly what this story turns on.
Finding it
The researcher spent time tampering with every parameter on the account settings page. A parameter is one of the named fields a form sends, such as firstname or lastname. The result was that there was no validation of first name and last name on the backend, so a name could be changed to something like <em>John</em>. Validation means the server checks what it receives and rejects anything that does not fit. Here it did not check, so it happily saved the angle brackets and the tag.
However, <script> tags and common XSS payloads were not allowed, because Cloudflare sat between the frontend and the backend, and the reflected name on the account page was filtered as well: < was escaped to <. Escaping means turning a character that has special meaning in HTML into a harmless written-out version. < is how you write a literal less-than sign in HTML so the browser shows it as text instead of starting a tag.
Because of this hardening the researcher stopped looking at the account portal. A few days later, while on the login page, they noticed something strange before typing credentials: the page greeted them with the name they had changed last time, John, but the <em> tag was missing from the visible output. Pressing CTRL+U to view the source showed the HTML tag enclosing the name, unfiltered.
In other words, the account page cleaned the name, but the login page did not. The visible greeting looked harmless because the tag was missing from it, but the raw source still contained it. That is the first crack in the wall.
Exploitation
Step 1: bypass the WAF by reaching the origin
The researcher researched how to bypass the Cloudflare WAF. The core idea, as described, is to look for the origin IP of the server. The simplest way given is to look for IP history on viewdns.org: if the website was initially set up without Cloudflare, an origin IP would be logged in the Internet history.
IP history services keep records of which address a domain name pointed to over time. If a site started life without a filter in front of it, its real address may still be in those old records. The filter only guards the front door; the old address is the back door.
An origin IP was found recorded on viewdns.org. Accessing the website from its origin IP and changing the name to the following payload got it past to the backend with no Cloudflare WAF involved:
<script>alert(\"Are you hungry?\")</script>
Line by line: <script> opens a script block, which tells the browser that what follows is code, not text. alert( is a built-in browser function that pops up a small dialog box. \"Are you hungry?\" is the message shown in that box. ) closes the function call, and </script> closes the script block. When the browser reaches this in a page, it runs the code and the box appears.
As expected, the alert box prompted when the login page was visited. This confirmed a self-XSS on the login page. At this point the researcher could make their own browser show a popup, and nobody else was affected yet.
Step 2: understand how the payload is stored and reflected
The report describes the storage and reflection behaviour as follows:
- After login, if the user ticks the Remember me box, the session is saved in a cookie named
rememberme, with an expiration time set to one year. - If a user visits the login page again, even without logging out first, they are greeted with the first name reflected on the login page.
A session is the site's way of remembering who you are between page loads. The rememberme cookie keeps that memory alive for a year, so the browser keeps presenting it long after the visit. The second point matters because it means the greeting, and therefore the stored name, appears on the login page even when the visitor is already logged in.
The consequence drawn is that if a login CSRF could be found, other users could be forced to log into the attacker's account, and on their next visit to the login page the attacker's XSS payload would execute. The attacker's name is the payload; the victim's browser would run it while looking at the login page.
Step 3: test the login CSRF token
Burp Suite was used to inspect the login request. As expected, a CSRF token was sent along with the credentials during the login request. Removing that token and re-sending the request failed.
This is the normal, healthy behaviour: the server checks the token and refuses the login when it is missing. The token is doing its job, which means a naive forged login will not work. The researcher had to find a way around the check rather than through it.
Step 4: reuse a token from another session
The researcher then tried what the report calls a "poor man CSRF". The reasoning given is that an anti-CSRF system normally ties the CSRF token to something that identifies the person performing the action. If the CSRF token is not tied to the user's session, an attacker can grab a valid CSRF token from the website and reuse it on the victim.
Think of the token as a cloakroom ticket. If the attendant checks that the ticket matches the coat you are collecting, a stolen ticket is useless. If the attendant only checks that the ticket is a real ticket, any valid one will do, and a ticket from your own coat works for someone else's.
Copying the CSRF token from a different browser session and reusing it resulted in a successful login to the account. This was the way to force the XSS on a user's login page. The token was real, just not the victim's, and the server accepted it.
Step 5: proof of concept
The following proof-of-concept code was used to exploit the chain:
<?php $html = file_get_contents('https://redacted.com/login'); preg_match('/name\=\”CSRF_TOKEN\” value\=\”(.*?)\”\', $html, $match); if( count ($match) ){ $token = $match[1]; echo '
<form name=”loginForm” target=”_blank”>
<!-—
form that contains my credentials + grabbed CSRF token
-->
</form>
<script>
window.forms.loginForm.submit();
</script>
'; }?>
Line by line, in plain words:
<?phpstarts a block of PHP, a language that runs on the server and produces a web page. Everything until?>is instructions for the server, not text for the visitor.$html = file_get_contents('https://redacted.com/login');downloads the login page and stores its raw HTML in a variable called$html. The attacker's server fetches the page the same way a browser would.preg_match('/name\=\”CSRF_TOKEN\” value\=\”(.*?)\”\', $html, $match);searches that HTML for the pattern of the hidden token field. The(.*?)part captures whatever sits between the quotes, and the result lands in$match.if( count ($match) ){checks that something was actually found before going on.$token = $match[1];takes the captured value, the token itself, out of the match array.echo 'begins printing the page that will be shown to the victim.- The
<form name=”loginForm” target=”_blank”>line starts an HTML form namedloginFormthat opens in a new tab. The comment between<!-—and-->marks where the attacker's credentials plus the grabbed token would go. <script>andwindow.forms.loginForm.submit();run a tiny script that finds the form and submits it automatically, with no click from the visitor.</script>closes it.'; }?>closes the printed text, theifblock and the PHP block.
The script fetches the login page, extracts the CSRF token with a regular expression, and prints a form containing the attacker's credentials plus the grabbed token, followed by a script that submits the form automatically. When a user visits the attacker's page, they are forced to log into the attacker's account, and on their next visit to the login page they are greeted with the attacker's XSS payload.
Root cause
The backend did not validate the first name and last name fields, so HTML could be stored in them. The account page escaped < to <, and Cloudflare blocked common payloads on the normal path, but the login page reflected the stored name without escaping it. The login CSRF token was not tied to the user's session, so a token obtained from one session could be reused in another. Together these allowed an attacker to store a script in their own profile and have it execute in a victim's browser after forcing the victim into the attacker's session.
Each piece on its own is a small flaw. The missing validation lets bad text in; the unescaped login page lets it out as code; the reusable token lets the attacker put a victim into the right place for the code to run. Chained, they become one serious bug.
Impact
An attacker could force a victim who visits the attacker's page to log into the attacker's account, and on the victim's next visit to the login page the stored payload would execute in the victim's browser.
Fix
A fix was deployed on 17 March 2020, after the reward was paid on 14 March 2020. The report does not describe what the fix changed.
Variants to test
- Look for stored HTML in profile fields that is escaped on one page but reflected unescaped on another, such as a login greeting. A positive result is a tag appearing in the page source where the visible output does not show it.
- Check whether the login CSRF token is tied to the session by copying a token from one browser session and reusing it in another. A positive result is a successful login with the reused token.
- Check IP history services such as viewdns.org for origin IPs of hosts behind a WAF. A positive result is the site responding on the origin IP and accepting payloads the WAF would block.
- Test whether the Remember me cookie keeps a session alive long enough for a stored payload to be reflected on a later visit to the login page. A positive result is the greeting appearing after the cookie is set and the user returns to the login page.
Timeline
| Date | Event |
|---|---|
| Feb 10, 2020 | Report sent |
| Feb 11, 2020 | Triage with Medium severity |
| Mar 14, 2020 | Reward $500 + $150 (bonus) |
| Mar 17, 2020 | Fix deployed |
Glossary
- Self-XSS: XSS that only affects the person who typed the payload, so it is usually not a security threat on its own.
- Persistent (stored) XSS: XSS where the payload is saved on the server and later shown to other visitors.
- CSRF (cross-site request forgery): tricking a visitor's browser into sending a request to another site without the visitor meaning to.
- Login CSRF: a CSRF attack that logs the victim into the attacker's account instead of their own.
- Cookie: a small piece of text a site stores in the browser and receives back on later visits, used to remember state such as a login.
- Session: the site's record of who you are across page loads, usually kept alive by a cookie.
- CSRF token: a random value placed in a form so the server can tell a genuine submission from a forged one.
- WAF (web application firewall): a filter in front of a site that blocks requests that look malicious.
- Cloudflare: a provider of such filtering and other web services.
- Origin IP: the real address of the server behind a filter, which can sometimes be reached directly.
- Escaping: converting characters with special meaning in HTML, such as
<, into harmless written-out forms such as<. - Validation: checking incoming data on the server and rejecting anything that does not fit the expected form.
- Parameter: a named field in a request or form, such as
firstname. - Payload: the piece of text or code an attacker wants the target to store or run.
- Burp Suite: a tool for watching and editing the requests a browser sends to a site.
- Proof of concept (PoC): a small piece of code or a set of steps that demonstrates the bug actually works.
- Regular expression: a pattern used to find and extract part of a text, such as a token inside HTML.
- PHP: a programming language that runs on a web server and produces pages.
CTRL+U: the browser shortcut that shows the raw HTML source of the current page.- Triage: the stage where a program reviews a report and decides whether it is valid and how severe it is.
- Severity: a rating of how serious a bug is, here Medium.
- Bug bounty: a program that pays researchers for reporting security bugs.