Skip to content
XSS Write-up Intermediate

How I found 5 store XSS on a private program. Each worth "1,016.66$"

Shahzad Sadiq Follow

Published on cybristerboy.blogspot.com

Bounty$5,083 View original

Hello Everyone, This blog is all about Cross Origin Resource Sharing (CORS) Vulnerability. In my one year of research, I found various type of bypass, that I would like to discuss.

Shahzad Sadiq (@ShahzadSadiq25), on cybristerboy.blogspot.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 is a write-up of five separate stored cross-site scripting findings on a single private bug bounty program. The program is not named; the author refers to it throughout as private-site.com. The findings were reported together, and the author states that each was worth "1,016.66$", for a total of 5,083.30 USD. The write-up was published on 30 May 2018 as the second post in the author's "Sharing Is Caring" series.

The five findings sit in different features of the same application:

  1. A comment body that is reflected on the user's own profile.
  2. A file attachment feature.
  3. A notification generated when a user performs an activity and a follower receives the notification.
  4. An endpoint that stores data on a user profile but blocks the < character.
  5. A feature where < and > are allowed but only width and height attributes are permitted.

The author deliberately withholds the exact term for the site in the fifth case so that others cannot use it as a clue.

Setup

The report does not describe account creation, roles or any specific tool versions. The only tooling mentioned is Burp Suite, used as an intercepting proxy and for its Intruder module. The workflow described is to capture requests in Burp, review the collected directories under Target -> Sitemap, and then send candidate requests to Intruder to fuzz a position.

No preconditions beyond a normal user account on the private program are stated. The author notes that the second finding was made at the end, when the program was about to close, and that the fifth took two to three days of work.

Finding it

Comment body

The author noticed that the comment body on private-site.com was reflected on the user's own profile. That reflection made the feature worth probing for stored XSS. Many payloads were tried and tested with no result. The author credits the saying "There is always a way to bypass" to zahid ali, who the author says bypassed the same feature three times on Facebook.

The idea that worked was to place the payload on the second or third line of the body rather than the first. The author says this technique was read in other researchers' posts. The payload stored when placed on the second line of the body was:

HTML
<svg/onload=alert(1337)>

Time spent on this finding is given as 9-10 hours.

File attachment

The author describes this as very easy to find, and expresses surprise that nobody else had found it. A file attachment feature was present. The upload request was captured in Burp and sent to Intruder, and every file extension was tried to see which were allowed. The allowed extensions were .txt, .png, .jpg and .xhtml.

The .xhtml extension is the interesting one: it was among the extensions the upload accepted. The proof of concept uploaded was:

XML
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>POC</title>
</head>
<body>
<p>This is a POC</p>
<script>alert(document.cookie)</script>
</body>
</html>

Time spent on this finding is given as 1 hour.

Notification

The author describes this type as a favourite and says it has been found three times on different programs. On private-site.com, when a user performs any activity, a follower user receives a notification. The HTML tag in the notification was not sanitised. The payload used was:

HTML
"><svg/onload=alert(1337)>

This made the notification a stored XSS.

Encoding bypass

On one endpoint, data was stored on a user profile, but the application blocked the < tag. The author captured the request in Burp and sent it to Intruder with a list of payloads to see whether the < sign could be bypassed:

Text
<
%3C
&lt
&lt;
&LT
&LT;
&#60
&#060
&#0060
&#00060
&#000060
&#0000060
&#X3C;
&#X03C;
&#X003C;
&#X0003C;
&#X00003C;
&#X000003C;
\x3c
\x3C
\u003c
\u003C

&#X000003C; worked. The payload used to get stored XSS on the user profile was:

HTML
">&#X000003C;svg/onload=alert(1337)>

Weird stored XSS

In this case < and > were allowed, but only the width and height attributes could be used. For example, < svg width=100 height=100> was allowed, but an event handler was blocked. The author spent two days on it and was about to give up, then gave it one more day.

The breakthrough came by accident. The request sent to Intruder was:

HTTP
POST /< svg width=100 hight=100>test

The author had forgotten that <svg width=100 hight=100> had been added to the request, so Intruder was trying different payloads on the test position. At one point the payload was:

HTML
<svg width=100 hight=100><script>alert(1)</script>

With that payload the stored XSS was truly stored. The author's explanation is that the filter was checking the first HTML tag only, which is described as really weird behaviour.

Root cause

Across the five findings the common theme is that user-controlled input reaches a page without adequate output encoding, and the filters that were present were narrow.

  • Comment body: the payload stored when placed on the second line of the body rather than the first. The report does not describe the filter itself.
  • File attachment: the extension allowlist included .xhtml, which is rendered as markup rather than served as an inert download. Allowing an active content type in an upload directory is the design mistake.
  • Notification: the HTML tag in the notification was not sanitised at all.
  • Encoding bypass: the filter blocked the literal <, but the encoded form &#X000003C; was accepted and the payload stored.
  • Weird stored XSS: the author's explanation is that the filter checked only the first HTML tag in the input, so the allowed <svg width=100 hight=100> tag satisfied it and the <script> that followed was stored.

In each case the existing defence was a blocklist or a partial check rather than context-aware output encoding, which is why each was bypassed.

Impact

All five are stored XSS, so the payload persists on the server and executes in the browser of any user who views the affected page. The report does not enumerate the affected users per finding, but the features imply different audiences: the comment body and profile data are viewed on the user's own profile, the notification is delivered to followers of the user who performed the activity, and the uploaded .xhtml file executes when someone opens it. The proof of concept for the attachment reads document.cookie. The author does not describe what was actually achieved beyond the alerts.

Fix

Based on the findings, the fixes would be: context-aware output encoding for the comment body, notifications and profile fields; decoding and normalising input before any character check; validating the whole input rather than only the first tag; and removing .xhtml (and any other active content type) from the upload allowlist, or serving uploads from a separate origin with a non-rendering content type.

Variants to test

  1. Multi-line input fields. Put the payload on the second or third line of a comment, bio or message body. A positive result is the payload stored and executed when the profile or comment is viewed.
  2. Upload extension fuzzing. Send the upload request to Intruder and try extensions such as .xhtml, .html, .svg and .xml. A positive result is an uploaded file that is served and rendered as markup in the site's origin.
  3. Notification and activity feeds. Trigger an activity that generates a notification for a follower and inject "><svg/onload=alert(1337)> into the fields that appear in the notification. A positive result is execution in the follower's session.
  4. Character-reference bypass. Where < is blocked, try the list of encodings above, including &#X000003C;. A positive result is the decoded < reaching the page and the payload executing.
  5. First-tag-only filters. Where only width and height are allowed, wrap the payload in an allowed tag such as <svg width=100 height=100> and follow it with <script>alert(1)</script>. A positive result is the script stored and executed.

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

What happened, in plain words

A security researcher spent time testing a website that paid money for finding security bugs. Such a website is called a private program: it is not open to everyone, and the researcher is not allowed to name it. Throughout the write-up the author simply calls it private-site.com.

On that site the researcher found five separate bugs of the same family: stored cross-site scripting, usually shortened to stored XSS. Each one was reported, and the author says each was worth "1,016.66$", for a total of 5,083.30 USD. The write-up was published on 30 May 2018 as the second post in a series the author calls "Sharing Is Caring".

Before going further, here is what stored XSS means, because everything below depends on it.

A website often shows text that one user typed to other users: a comment, a profile description, a notification. The browser cannot tell the difference between text a person typed and instructions that make the page do something. If the site puts user text into a page without cleaning it, and that text contains something the browser reads as a command, the browser will run it. When the text is saved on the server and shown again later to anyone who opens the page, the bug is stored: the harmful text waits on the server until a victim loads the page.

The classic harmless demonstration is a pop-up box. The command alert(1337) makes the browser show a small dialog with the number 1337 in it. It does nothing harmful, but it proves that the browser ran code that came from the attacker rather than from the site. A real attacker would use the same hole to read the victim's session cookie (a small piece of data the browser keeps to prove who is logged in) and take over the account.

The five findings sit in five different features of the same application:

  1. A comment body that is shown on the user's own profile.
  2. A file attachment feature.
  3. A notification generated when a user performs an activity and a follower receives the notification.
  4. A place that stores data on a user profile but blocks the < character.
  5. A feature where < and > are allowed but only width and height attributes are permitted.

In the fifth case the author deliberately does not name the exact feature, so that other people cannot use it as a clue to find the same site.

The tools and the basic idea

The report does not describe how accounts were created, what roles existed, or which versions of any tool were used. The only tool mentioned is Burp Suite, a program that sits between your browser and a website and lets you look at, change and replay the requests your browser sends. Two parts of it are used here:

  • The proxy, which captures requests so you can inspect them.
  • Intruder, which takes one captured request and automatically repeats it many times, each time putting a different value into one chosen spot. That spot is called the position. It is the standard way to try a long list of candidate inputs quickly.

The workflow described is: capture requests in Burp, look at the collected directories under Target -> Sitemap, and then send candidate requests to Intruder to fuzz a position. "Fuzzing" simply means trying many variations automatically and watching for one that behaves differently.

No preconditions beyond a normal user account on the private program are stated. The author notes that the second finding was made at the end, when the program was about to close, and that the fifth took two to three days of work.

Finding it

1. Comment body

The author noticed that the comment body on private-site.com was shown again ("reflected") on the user's own profile. That is the interesting part: text you type in one place reappears in another page, which means the site is storing it and printing it back. Anywhere that happens is worth testing for stored XSS, because whatever you type may end up inside the page's instructions.

Many payloads were tried and tested with no result. A payload here just means the piece of text you submit in the hope that the browser will treat it as a command. The author credits the saying "There is always a way to bypass" to zahid ali, who the author says bypassed the same feature three times on Facebook.

The idea that worked was to place the payload on the second or third line of the body rather than the first. The author says this technique was read in other researchers' posts. The payload stored when placed on the second line of the body was:

HTML
<svg/onload=alert(1337)>

Line by line, in plain words:

  • <svg ...> starts an SVG element. SVG is a format for drawing pictures that browsers understand directly inside a web page.
  • onload= is an event handler: an attribute that tells the browser "when this element has finished loading, do the following".
  • alert(1337) is the following: show a pop-up with 1337 in it.
  • The / before onload is a shorthand way of writing the tag so that the browser still accepts the attribute.

So the whole thing says: draw an (empty) picture, and as soon as it loads, run this command. If the site stores that text and later prints it into a page without cleaning it, every visitor's browser runs the pop-up.

Why put it on the second line? The author's result suggests the site's cleaning step only looked at the first line of the comment. Anything after the first line slipped past. The report does not describe the filter itself, so that is as far as the evidence goes.

Time spent on this finding is given as 9-10 hours.

2. File attachment

The author describes this as very easy to find, and expresses surprise that nobody else had found it. A file attachment feature was present, meaning users could upload files. The upload request was captured in Burp and sent to Intruder, and every file extension was tried to see which were allowed. An extension is the part of a filename after the last dot, such as .txt or .jpg; it is how a computer guesses what kind of file it is looking at.

The allowed extensions were .txt, .png, .jpg and .xhtml.

The .xhtml extension is the interesting one. XHTML is a way of writing a web page using strict XML rules, and it was among the extensions the upload accepted. Because the file sits on the same site, that script runs with the site's identity, exactly as if the site itself had written it. Allowing an active content type like this in an upload area is the design mistake.

The proof of concept uploaded was:

XML
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>POC</title>
</head>
<body>
<p>This is a POC</p>
<script>alert(document.cookie)</script>
</body>
</html>

Line by line, in plain words:

  • <?xml version="1.0" encoding="iso-8859-1"?> declares that this is an XML document and which character encoding it uses. Character encoding is the rulebook that maps bytes to letters.
  • The <!DOCTYPE html PUBLIC ...> line tells the browser which flavour of markup to expect, here XHTML 1.0 Transitional.
  • <html ...> opens the page and sets its language and namespace.
  • <head> and <title>POC</title> give the page a title, shown in the browser tab.
  • <body> starts the visible part of the page.
  • <p>This is a POC</p> is an ordinary paragraph of text, there so the page looks normal.
  • <script>alert(document.cookie)</script> is the actual test. document.cookie is the browser's way of reading the cookies that belong to the current site, and alert(...) shows them in a pop-up. If the pop-up appears, the uploaded file is running code in the site's own context, which is the whole point of the proof.

Time spent on this finding is given as 1 hour.

3. Notification

The author describes this type as a favourite and says it has been found three times on different programs. On private-site.com, when a user performs any activity, a follower user receives a notification. A notification is a message the site generates automatically and shows to someone else, which makes it a perfect place for stored XSS: the attacker writes the text once, and it is delivered to other people.

The HTML tag in the notification was not sanitised. Sanitising means cleaning input so that anything the browser would treat as an instruction is removed or neutralised. Here nothing was cleaned. The payload used was:

HTML
"><svg/onload=alert(1337)>

Line by line, in plain words:

  • "> closes whatever attribute the site had already opened in its own HTML, and closes the tag. This is called "breaking out" of the context: the attacker first ends the piece of markup the site wrote, so that what follows is treated as fresh markup rather than as text inside an attribute.
  • <svg/onload=alert(1337)> is the same SVG-with-event-handler trick as in the first finding: draw an empty picture and run the pop-up when it loads.

This made the notification a stored XSS.

4. Encoding bypass

On one endpoint, data was stored on a user profile, but the application blocked the < tag. An endpoint is simply one address on the site that accepts a particular kind of request, like one counter in a large building. The < character is the one that starts every HTML tag, so blocking it is a common, crude defence.

The author captured the request in Burp and sent it to Intruder with a list of payloads to see whether the < sign could be bypassed. The idea is that the browser understands many different spellings of the same character, and a filter that only checks for the literal < may miss the others:

Text
<
%3C
&lt
&lt;
&LT
&LT;
&#60
&#060
&#0060
&#00060
&#000060
&#0000060
&#X3C;
&#X03C;
&#X003C;
&#X0003C;
&#X00003C;
&#X000003C;
\x3c
\x3C
\u003c
\u003C

Line by line, in plain words:

  • < is the plain character.
  • %3C is the same character written in URL encoding, the scheme that lets special characters travel inside web addresses.
  • &lt and &lt; are HTML character references: a way of writing a character by name. lt stands for "less than".
  • &LT and &LT; are the same, in capitals; HTML references are not case-sensitive.
  • &#60, &#060, &#0060, &#00060, &#000060 and &#0000060 are the same character written by its numeric code, 60, with different numbers of leading zeros. Browsers accept the padding.
  • &#X3C;, &#X03C;, &#X003C;, &#X0003C;, &#X00003C; and &#X000003C; are the same numeric reference written in hexadecimal (base 16), where 3C equals 60 in decimal, again with varying zero padding.
  • \x3c, \x3C, \u003c and \u003C are escape sequences used in programming languages to represent the same character.

&#X000003C; worked. The payload used to get stored XSS on the user profile was:

HTML
">&#X000003C;svg/onload=alert(1337)>

Line by line, in plain words:

  • "> breaks out of the attribute the site had opened, as in the notification finding.
  • &#X000003C; is the < character written as a hexadecimal HTML reference. The site's filter did not recognise it as a <, so it let it through.
  • svg/onload=alert(1337)> completes the tag once the browser has decoded the reference back into a real <.

The lesson is that the filter blocked the literal character but did not decode or normalise the input before checking it. The browser, however, does decode it, so the character arrives as a real < and the tag is built.

5. Weird stored XSS

In this case < and > were allowed, but only the width and height attributes could be used. For example, < svg width=100 height=100> was allowed, but an event handler was blocked. The author spent two days on it and was about to give up, then gave it one more day.

The breakthrough came by accident. The request sent to Intruder was:

HTTP
POST /< svg width=100 hight=100>test

Line by line, in plain words:

  • POST is the type of request used when a browser sends data to the server, for example when submitting a form.
  • / is the address being requested.
  • < svg width=100 hight=100> is the allowed-looking tag the author had put into the request. Note the spelling hight; it is written that way in the request.
  • test is the word the author meant Intruder to replace with each candidate payload.

The author had forgotten that <svg width=100 hight=100> had been added to the request, so Intruder was trying different payloads on the test position. At one point the payload was:

HTML
<svg width=100 hight=100><script>alert(1)</script>

Line by line, in plain words:

  • <svg width=100 hight=100> is the tag the filter was willing to accept: an SVG picture with a width and a height.
  • <script>alert(1)</script> is a script block that shows a pop-up with 1 in it. It is a separate element that follows the allowed one.

With that payload the stored XSS was truly stored. The author's explanation is that the filter was checking the first HTML tag only, which is described as really weird behaviour. In other words, the filter looked at the beginning of the input, saw an allowed tag, and stopped checking; everything after it was stored untouched.

Why it worked

Across the five findings the common theme is that user-controlled input reaches a page without adequate output encoding, and the filters that were present were narrow. Output encoding means converting text so that the browser displays it as text rather than reading it as instructions.

  • Comment body: the payload stored when placed on the second line of the body rather than the first.
  • File attachment: the extension allowlist included .xhtml, which is rendered as markup rather than served as an inert download. Allowing an active content type in an upload directory is the design mistake.
  • Notification: the HTML tag in the notification was not sanitised at all.
  • Encoding bypass: the filter blocked the literal <, but the encoded form &#X000003C; was accepted and the payload stored.
  • Weird stored XSS: the author's explanation is that the filter checked only the first HTML tag in the input, so the allowed <svg width=100 hight=100> tag satisfied it and the <script> that followed was stored.

In each case the existing defence was a blocklist or a partial check rather than context-aware output encoding, which is why each was bypassed. A blocklist is a list of things to forbid; it only stops what someone thought of in advance.

What it means for the site and its users

All five are stored XSS, so the payload persists on the server and executes in the browser of any user who views the affected page. The report does not enumerate the affected users per finding, but the features imply different audiences: the comment body and profile data are viewed on the user's own profile, the notification is delivered to followers of the user who performed the activity, and the uploaded .xhtml file executes when someone opens it. The proof of concept for the attachment reads document.cookie. The author does not describe what was actually achieved beyond the alerts.

How it should be fixed

Based on the findings, the fixes would be: context-aware output encoding for the comment body, notifications and profile fields; decoding and normalising input before any character check; validating the whole input rather than only the first tag; and removing .xhtml (and any other active content type) from the upload allowlist, or serving uploads from a separate origin with a non-rendering content type. Context-aware means the encoding must match where the text ends up: inside an attribute, inside a script, or as plain page text each need different treatment.

Things to try yourself

  1. Multi-line input fields. Put the payload on the second or third line of a comment, bio or message body. A positive result is the payload stored and executed when the profile or comment is viewed.
  2. Upload extension fuzzing. Send the upload request to Intruder and try extensions such as .xhtml, .html, .svg and .xml. A positive result is an uploaded file that is served and rendered as markup in the site's origin.
  3. Notification and activity feeds. Trigger an activity that generates a notification for a follower and inject "><svg/onload=alert(1337)> into the fields that appear in the notification. A positive result is execution in the follower's session.
  4. Character-reference bypass. Where < is blocked, try the list of encodings above, including &#X000003C;. A positive result is the decoded < reaching the page and the payload executing.
  5. First-tag-only filters. Where only width and height are allowed, wrap the payload in an allowed tag such as <svg width=100 height=100> and follow it with <script>alert(1)</script>. A positive result is the script stored and executed.

Glossary

  • Stored XSS (cross-site scripting): a bug where text a user submits is saved by the site and later shown to other users in a way that makes their browsers run it as code.
  • Payload: the piece of text an attacker submits, hoping the browser will treat it as an instruction.
  • Private program: a bug bounty programme that is not open to the public and whose target may not be named.
  • Bug bounty: a scheme where a company pays researchers for reporting security bugs responsibly.
  • Burp Suite: a tool that sits between browser and website, letting you inspect, change and replay requests.
  • Proxy: a program that relays traffic between two parties and can record or alter it on the way.
  • Intruder: the part of Burp that repeats one request many times, each time substituting a different value into a chosen position.
  • Position: the spot in a request that Intruder replaces with each candidate value.
  • Fuzzing: automatically trying many variations of an input and watching for one that behaves differently.
  • Endpoint: one address on a site that accepts a particular kind of request.
  • Request: the message a browser sends to a server asking for a page or submitting data.
  • POST: the request type normally used to send data to a server, such as a form submission.
  • HTML tag: the markup that tells a browser what an element is, written between < and >.
  • Attribute: a setting written inside a tag, such as width=100.
  • Event handler: an attribute that tells the browser to run something when an event happens, such as onload.
  • SVG: a picture format that browsers understand directly inside a web page.
  • Script: code that the browser runs, usually written between <script> and </script>.
  • Alert: a browser pop-up used in tests to prove that code ran.
  • Cookie: a small piece of data a browser keeps for a site, often used to prove who is logged in.
  • Session cookie: the cookie that identifies a logged-in session; stealing it can let an attacker act as the victim.
  • Sanitising: cleaning input so that anything the browser would treat as an instruction is removed or neutralised.
  • Output encoding: converting text so the browser displays it as text rather than reading it as instructions.
  • Context-aware encoding: encoding that matches where the text ends up, such as inside an attribute versus as page text.
  • Blocklist: a list of things to forbid, which only stops what someone thought of in advance.
  • Allowlist: a list of things that are permitted, with everything else refused.
  • Filter: the code that inspects input and decides whether to accept, change or reject it.
  • Normalise: to convert input into one standard form before checking it.
  • Decode: to turn an encoded representation back into the character it stands for.
  • HTML character reference: a way of writing a character by name or number, such as &lt; or &#60;.
  • Hexadecimal: base-16 numbering, where 3C equals 60 in decimal.
  • URL encoding: the scheme that lets special characters travel inside web addresses, such as %3C for <.
  • Escape sequence: a short code in a programming language that stands for a character, such as \x3c or \u003c.
  • Extension: the part of a filename after the last dot, such as .txt or .jpg, used to guess the file type.
  • XHTML: a way of writing web pages using strict XML rules; browsers render it as a page and run scripts inside it.
  • XML: a general format for structured documents, of which XHTML is one flavour.
  • DOCTYPE: a declaration at the top of a document saying which flavour of markup it uses.
  • Character encoding: the rulebook that maps bytes to letters, such as iso-8859-1.
  • Namespace: a label that says which vocabulary a markup element belongs to.
  • Origin: the combination of scheme, host and port that a browser uses to decide which site a page belongs to; scripts from one origin should not be able to read another's data.
  • Reflected: shown back on a page shortly after being submitted, rather than only stored.
  • Proof of concept (POC): a minimal demonstration that a bug is real.
  • Notification: a message a site generates automatically and shows to another user.
  • Follower: a user who has subscribed to another user's activity and receives their notifications.
  • Profile: the page on a site that shows information about a user.
  • Comment body: the main text of a comment, as opposed to its author or date.
  • File attachment: a feature that lets users upload files to a site.
  • Sitemap (in Burp): the view that lists every address the proxy has seen, grouped by directory.
  • Directory: a folder-like part of a site's address structure.
  • Bypass: getting past a defence without removing it.

More by Shahzad Sadiq

View all

1 more disclosed report, best first.

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.