Skip to content
XSS Write-up Intermediate

Bug Bounty Writeup: Stored XSS Vulnerability WAF Bypass

The app failed to encode double quotes in external links inserted into custom emails, allowing an attacker to inject an onmouseover attribute into the generated anchor tag. An attacker could execute arbitrary JavaScript in another user's browser when they hover over the link.

Rafael Silva "lopseg Follow

Published on medium.com

{{media:0}}

Rafael Silva "lopseg", on medium.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. 4 min read.

Context

The target is an app that lets users customise the Custom Receipts and Abandoned Cart emails sent to their customers. Part of that customisation is the ability to insert links to external websites inside those emails. The app builds an anchor tag from the URL the user supplies, and the report focuses on what happens when that URL contains a double quote.

The researcher is Rafael Silva, who publishes as "lopseg". The report is a short write-up of a stored cross-site scripting (XSS) issue in that link-insertion feature, together with a payload that gets past the web application firewall (WAF).

Rafael Silva "lopseg"
Rafael Silva "lopseg" From the original on medium.com

Setup

Reproduction needs two accounts on the same app:

  1. Account 1, the owner.
  2. Account 2, an invited admin.

A tool such as Burp Suite is used to intercept and edit the request that saves the link. No versions, endpoints or parameter names are given in the report.

Finding it

The app does not properly encode double quotes when they are part of an external link. Because the URL is placed inside the href attribute of a generated anchor tag, a quote in the URL closes that attribute early, and anything after it is treated as further attributes of the same tag. The report demonstrates this with a plain URL:

Text
http://example.com"%20test=test

Inserted as an external URL, it produces this anchor tag:

HTML
<a href="http://example.com" test=test"> CLICK ME </a>

The href now ends at http://example.com, and test=test has become an attribute of the anchor. That is the primitive: arbitrary attributes can be added to the generated tag. From there the researcher moved on to an event handler attribute that runs JavaScript.

Exploitation

Step 1: create the link as the invited admin

As account 2, write AAAAAAAAAAAAAAAAAAAA in the editor, select the text and click the Link button, then paste http://example.com as the URL. This is the normal, legitimate use of the feature; the malicious value is substituted in the next step.

Step 2: intercept and replace the URL

Intercept the request with a tool such as Burp Suite and replace http://example.com in the body of the request with the following payload:

Text
http:falselink.com;"onmouseover%20=%0az=top;z[/al/.source%2b/ert/.source](8);//test.com/

The payload is built to get past the WAF and to add an onmouseover handler to the generated anchor. The handler fires when a user moves the mouse over the link.

The report shows the resulting anchor tag as the proof of concept:

HTML
<a href="http://example.com;" onmouseover="z=top;z[/al/.source%2b/ert/.source](8);//test.com/"

Step 3: trigger it as the owner

Log in as account 1, go to the vulnerable page and hover the mouse over the AAAAAAAAAAAAAAAAAAAA link. The onmouseover handler runs in the owner's browser.

Root cause

The app fails to encode double quotes in the external URL before placing it inside the href attribute of the anchor tag. A quote therefore terminates the attribute and lets the user inject new attributes, including event handlers. The WAF did not stop the payload; the report does not explain why. The report does not describe the WAF's rules or why they missed this form.

Impact

The stored payload runs custom JavaScript in other users' browsers. According to the report, a malicious user can perform unwanted actions, such as escalating their privileges and carrying out read and write actions on behalf of other users, because XSS lets an attacker bypass the Same-origin Policy. The payload executes when another user, here the owner, views the page and hovers the link.

Fix

The general lesson it draws is that web applications must properly encode and sanitise user input to prevent this class of vulnerability; for this feature, that means encoding double quotes (and the other characters that matter inside an attribute) in the URL before it is written into the anchor tag.

Variants to test

  1. Put a double quote in any field that ends up inside an HTML attribute (link URLs, image sources, titles, alt text) and check whether the generated markup closes the attribute early. A positive result is a tag where your text has become a separate attribute.
  2. Try event-handler attributes such as onmouseover on the injected attribute and confirm the handler fires in a second account's browser. A positive result is JavaScript executing under the victim's session.
  3. Where a WAF blocks obvious payloads, split keywords into concatenated string fragments and separate attribute names from values with encoded whitespace, as in the payload above. A positive result is the same execution with the request accepted.
  4. Test the same injection in email templates and other stored content that is rendered to other users, not just to the author. A positive result is the payload persisting and firing for a different account.

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

What happened, in plain words

A researcher called Rafael Silva, who publishes under the name "lopseg", found a security hole in an app that lets shop owners customise the emails they send to their customers. The app has a feature where you can put a link to an outside website inside those emails. When the app builds the clickable link, it takes the web address you typed and drops it into the page without cleaning it up properly. If you put a double quote character (") in that address, the app treats everything after the quote as extra instructions for the browser. The researcher used this to sneak in a small piece of JavaScript, the programming language that runs inside web pages, so that it runs in someone else's browser when they move their mouse over the link. That kind of attack is called cross-site scripting, or XSS. Because the malicious link is saved in the app and shown to other people later, it is called stored XSS. The researcher also had to get the attack past the app's web application firewall (WAF), a security filter that inspects incoming requests and blocks ones that look dangerous, so the final payload was written in a slightly disguised form.

Rafael Silva "lopseg"
Rafael Silva "lopseg" From the original on medium.com

The app and the feature

The target is an app that lets users customise two kinds of emails sent to their customers: Custom Receipts and Abandoned Cart emails. A receipt email is the confirmation a customer gets after buying something. An abandoned cart email is a reminder sent when someone puts items in a shopping basket but leaves without paying. Both are ordinary marketing and transactional emails, and the app gives the shop owner a small editor to change how they look.

Part of that editor lets you insert a link to an external website. Under the hood, the app turns the web address you supply into an anchor tag, the piece of HTML (the language web pages are written in) that makes text clickable. An anchor tag looks like this: <a href="https://example.com">click me</a>. The href attribute holds the destination address, and the text between the tags is what the reader sees and clicks.

The report focuses on what happens when the address you supply contains a double quote. The researcher is Rafael Silva, publishing as "lopseg", and the write-up is short: it describes the stored XSS in the link-insertion feature and gives a payload that gets past the WAF.

Setting up

To reproduce the issue you need two accounts on the same app:

  1. Account 1, the owner of the app.
  2. Account 2, an invited admin.

You also need a tool such as Burp Suite. Burp Suite is a program that sits between your browser and the website and lets you pause, read and edit the requests your browser sends before they reach the server. Think of it as a postal worker who lets you open a letter, change a word, and seal it again before delivery. The report does not give versions, endpoints or parameter names, so the exact URLs and field names are not part of this write-up.

Finding the problem

The app does not properly encode double quotes when they are part of an external link. Encoding here means converting characters that have a special meaning in HTML into a safe form, so that the browser treats them as plain text rather than as instructions. Because the URL is placed inside the href attribute of the generated anchor tag, a quote in the URL closes that attribute early. Everything after the quote is then read by the browser as further attributes of the same tag.

The report demonstrates this with a plain URL:

Text
http://example.com"%20test=test

Line by line: http://example.com is an ordinary web address. The " is a double quote, the character that ends the href value early. %20 is the URL-encoded form of a space, so the browser sees a space there. test=test is a made-up attribute name and value, used only to show that it lands inside the tag.

Inserted as an external URL, that value produces this anchor tag:

HTML
<a href="http://example.com" test=test"> CLICK ME </a>

Reading it in plain words: the tag opens with <a. The href attribute now ends at http://example.com, because the quote right after it closes the value. Then test=test appears as a separate attribute of the anchor, which the app never intended. The stray "> at the end is left over from the original markup. CLICK ME is the visible link text. The important point is that the researcher can now add any attribute to the generated tag, not just test=test. From there the next step was to add an attribute that runs JavaScript.

Carrying out the attack

Step 1: create the link as the invited admin

As account 2, write AAAAAAAAAAAAAAAAAAAA in the editor, select the text and click the Link button, then paste http://example.com as the URL. This is the normal, legitimate use of the feature: you highlight some text, press the link button, and give it an address. The malicious value is swapped in during the next step, so this step just creates a request you can intercept and edit.

Step 2: intercept and replace the URL

Intercept the request with a tool such as Burp Suite and replace http://example.com in the body of the request with the following payload:

Text
http:falselink.com;"onmouseover%20=%0az=top;z[/al/.source%2b/ert/.source](8);//test.com/

Line by line, in plain words:

  • http:falselink.com; is the start of the address, ending with a semicolon. It is there to look like a URL and to close off the href value.
  • " is the double quote that ends the href attribute early, exactly as in the simple example above.
  • onmouseover is the name of an HTML event handler attribute. An event handler is a piece of JavaScript that the browser runs when something happens, here when the mouse moves over the element.

The report shows the resulting anchor tag as the proof of concept:

HTML
<a href="http://example.com;" onmouseover="z=top;z[/al/.source%2b/ert/.source](8);//test.com/"

In plain words: the href now ends at http://example.com;, and a new onmouseover attribute has been added. Its value is the JavaScript that runs when the mouse moves over the link. The proof of concept is cut off at the end in the report, but the important part is visible: the injected attribute is now part of the tag.

Step 3: trigger it as the owner

Log in as account 1, go to the vulnerable page and hover the mouse over the AAAAAAAAAAAAAAAAAAAA link. The onmouseover handler runs in the owner's browser. In other words, the code the researcher planted is now executing as if the owner had run it themselves.

Why it works

The app fails to encode double quotes in the external URL before placing it inside the href attribute of the anchor tag. A quote therefore ends the attribute and lets the user inject new attributes, including event handlers. The WAF did not stop the payload; the report does not explain why.

What an attacker could do

The stored payload runs custom JavaScript in other users' browsers. According to the report, a malicious user can perform unwanted actions, such as escalating their privileges and carrying out read and write actions on behalf of other users, because XSS lets an attacker bypass the Same-origin Policy. The Same-origin Policy is a browser rule that stops a page from one website reading data from another; XSS sidesteps it because the malicious code is running inside the trusted page, so the browser treats it as legitimate. The payload executes when another user, here the owner, views the page and hovers the link.

The fix

The general lesson it draws is that web applications must properly encode and sanitise user input to prevent this class of vulnerability. For this feature, that means encoding double quotes, and the other characters that matter inside an attribute, in the URL before it is written into the anchor tag. Sanitising means removing or neutralising anything dangerous before it is stored or displayed.

Other places to look

  1. Put a double quote in any field that ends up inside an HTML attribute (link URLs, image sources, titles, alt text) and check whether the generated markup closes the attribute early. A positive result is a tag where your text has become a separate attribute.
  2. Try event-handler attributes such as onmouseover on the injected attribute and confirm the handler fires in a second account's browser. A positive result is JavaScript executing under the victim's session.
  3. Where a WAF blocks obvious payloads, split keywords into concatenated string fragments and separate attribute names from values with encoded whitespace, as in the payload above. A positive result is the same execution with the request accepted.
  4. Test the same injection in email templates and other stored content that is rendered to other users, not just to the author. A positive result is the payload persisting and firing for a different account.

Glossary

  • XSS (cross-site scripting): a security hole where an attacker gets their own JavaScript to run inside another user's browser session on a trusted website.
  • Stored XSS: XSS where the malicious input is saved on the server and shown to other users later, rather than reflected back only to the person who sent it.
  • WAF (web application firewall): a filter that inspects incoming web requests and blocks ones that look like attacks.
  • HTML: the language web pages are written in, made of tags and attributes.
  • Tag: a piece of HTML markup such as <a> or </a> that tells the browser what an element is.
  • Attribute: a name and value inside an HTML tag, such as href="...", that configures the element.
  • Anchor tag: the HTML element <a> that makes text clickable and points it at a URL.
  • href: the attribute of an anchor tag that holds the destination address.
  • Event handler: an attribute such as onmouseover whose value is JavaScript the browser runs when a particular event happens.
  • onmouseover: an event handler that fires when the mouse pointer moves over an element.
  • JavaScript: the programming language that runs inside web browsers and makes pages interactive.
  • Encoding: converting characters that have a special meaning into a safe form so they are treated as plain text.
  • URL encoding: writing special characters as % followed by two hex digits, for example %20 for a space and %0a for a line break.
  • Sanitising: removing or neutralising dangerous content from user input before it is stored or displayed.
  • Same-origin Policy: a browser rule that stops a page from one site reading data from another site.
  • Burp Suite: a tool that sits between your browser and a website so you can pause, read and edit requests.
  • Request: the message your browser sends to a server asking for a page or submitting data.
  • Endpoint: the specific address on a server that a request is sent to.
  • Parameter: a named value sent with a request, such as a field in a form.
  • Payload: the piece of input an attacker sends to trigger a vulnerability.
  • Proof of concept (POC): a small demonstration that shows a vulnerability is real.
  • Privilege escalation: gaining more permissions on a system than you were given.
  • Session: the period during which a website remembers who you are, usually via a cookie or token.
  • Cookie / token: a small piece of data the browser stores and sends back to the site so the server can recognise your session.
  • API: a way for one piece of software to talk to another, usually over the web, by sending requests and receiving responses.
  • Admin: a user account with extra permissions to manage a workspace or app.
  • Custom Receipts: emails the app lets a shop owner customise, sent to customers after a purchase.
  • Abandoned Cart emails: reminder emails sent to customers who left items in a basket without buying.
  • alert: a built-in browser function that shows a pop-up message box.
  • Variable: a named storage slot in a program, such as z in the payload.
  • Comment (in code): text the browser ignores, such as everything after // in JavaScript.

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.