Skip to content
XSS Write-up Intermediate

XSS Filter Evasion

A reflected XSS vulnerability existed because a parameter was reflected unquoted inside an input tag, allowing attribute injection. A WAF blocked event handlers and stripped JavaScript keywords, but the attacker bypassed it by nesting keywords so that the application's own stripping produced a working payload.

m0z Follow

Published on m0z.co

You’re testing a web application and finally find an endpoint that is reflecting HTML code. You drop your XSS payload and BOOM!

m0z, on m0z.co

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

This write-up describes a reflected XSS vulnerability found on a site the author was testing, in an endpoint that reflected a GET parameter into the value of an HTML input tag. The author notes that the endpoint was obvious and had clearly been tested by many security researchers before, and that the same vulnerability forms the second challenge on his own challenge site. The write-up was published on 17 June 2019.

The feature itself is ordinary: a parameter is echoed back into the page inside an input element. What makes the case interesting is that a web application firewall (WAF) sat in front of the application and blocked the usual payloads, so the bypass came from the interaction between the WAF and a second, application-level filter.

Setup

The write-up does not describe any accounts, roles, tooling or versions. The only precondition that matters is the shape of the reflection and the presence of two filters in sequence: a WAF that inspects the request before the application sees it, and an application-side keyword stripper that runs afterwards.

Finding it

The author noticed that the site reflected the input of a parameter inside an input tag, in a form that looked like this:

HTML
<input name="param1" value=$param1>

The value of the GET parameter param1 is placed into the input's value. The input is escaped correctly, so the tag cannot be closed, and the characters > and < are completely blocked by the WAF, which makes it effectively impossible to spawn new HTML tags.

The detail that changes everything is that $param1 is not enclosed in any quotations. Because of that, a space is enough to spawn a new attribute on the same input tag. The obvious next step is to add a space and use the onfocus event handler together with the autofocus attribute, so that the JavaScript runs as soon as a victim visits the link. In practice, the WAF stood in the way.

Exploitation

Step 1: Understand what the WAF does

The WAF performed two distinct actions:

  1. It completely blocked any request containing HTML, which included all event handlers such as onfocus.
  2. It stripped key JavaScript functions such as alert, prompt and console.log, and pretty much everything needed for an XSS proof of concept. It even stripped document.cookie.

The author tried a lot of different handlers, and none of them were allowed. There was no magical way around the blocking of event handlers, and the write-up is explicit that this part was not bypassed.

Step 2: Notice the order of the two filters

The solution lay in the application's additional security measures, namely the stripping of keywords such as alert and prompt. The WAF reads the request data before the web application ever gets its hands on it, so it can discard malicious requests safely. The application then strips the JavaScript keywords, and that happens afterwards.

The idea was therefore to build a payload that the WAF would not block, but which, once the application had stripped those keywords, would become a working payload.

Step 3: Package the payload with alert

Since onfocus was blocked and alert and document.cookie were stripped, the author used alert as the packaging: it lets the payload pass the WAF safely and is then discarded by the application. The final payload was:

Text
 oalertnfocus=alalertert(documealertnt.cookie) autofocus

Each occurrence of alert is removed by the application's keyword stripping, and what remains is a valid attribute on the input tag. After the alert keyword is stripped, the full input element on the page becomes:

HTML
<input name="param1" value= onfocus=alert(document.cookie) autofocus>

The leading space in the payload closes the unquoted value attribute, onfocus and autofocus are assembled from the fragments left after stripping, and the handler calls alert(document.cookie) when the input receives focus automatically. The payload was built so the WAF would not block it, and the application's stripping then produced a working payload.

Root cause

The mistake is the ordering and the nature of the two filters. The WAF blocks on the raw request, before the application processes it, while the application performs its own sanitisation afterwards. A payload that is harmless to the WAF can therefore be transformed by the application's stripping step into something dangerous. The stripping is a blacklist of keywords rather than a structural defence, and removing substrings from attacker-controlled input can reassemble new tokens, which is exactly what happened here. The unquoted attribute value in the template is the second contributing factor: it allows a new attribute to be introduced with nothing more than a space. The write-up does not state how the application implemented the stripping.

Impact

The result is a reflected XSS: an attacker who gets a victim to visit a crafted link runs JavaScript in the victim's session on the affected site. The payload shown calls alert(document.cookie).

Fix

Based on the root cause, the fixes would be to quote the reflected value in the template, so that a space cannot introduce a new attribute, and to stop relying on keyword stripping as a security control, since removing substrings from attacker input can reassemble dangerous tokens. Context-aware output encoding of the parameter, applied by the application itself rather than only by the WAF, would remove the underlying reflection problem.

Variants to test

  1. Unquoted attribute reflections: look for parameters echoed into value=$param without quotes. A positive result is that a space plus an attribute name appears as a new attribute in the rendered HTML.
  2. Filter ordering: send a payload containing a blocked keyword split by a benign token, such as alert inserted inside an attribute or function name, and check whether the application removes the token after the WAF has passed the request. A positive result is that the response contains the reassembled dangerous string.
  3. Keyword stripping of document.cookie: check whether the application removes it from input. A positive result is that the string disappears from the response while the surrounding payload survives.
  4. Event handler blocking: try onfocus with autofocus and other handlers. A positive result is that the handler is accepted and fires when the element receives focus.
  5. Character blocking: confirm whether < and > are blocked. A positive result is that they are rejected, which forces attribute-based payloads on an existing tag rather than new tags.

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

What happened, in plain words

A security researcher was testing a website and found a place where the site takes something you type into the address bar and copies it into the page you see. That kind of copying is called a reflection, and it is the raw material for a very common bug called cross-site scripting, or XSS. The idea behind XSS is simple: if a site copies your input into its own page without treating it as plain text, you can make the site run code of your choosing in the browser of anyone who opens your link.

On this site the usual tricks did not work, because a web application firewall (WAF) stood in front of the application and blocked them. A WAF is a filter that sits between the visitor and the website and inspects every request before the website itself sees it, a bit like a bouncer at a door who checks your bag before you go in. The researcher found that the WAF blocked anything containing HTML and also removed certain JavaScript words from requests. But the website had a second filter of its own, applied after the WAF had already let the request through, and that second filter removed the same JavaScript words again. By hiding the dangerous words inside themselves, the researcher built a request that looked harmless to the WAF, and that the website's own filter then turned into a working attack.

The write-up was published on 17 June 2019 and describes a reflected XSS. The same vulnerability is the second challenge on the author's own challenge site. The author notes that the endpoint was obvious and had clearly been tested by many researchers before.

The beginning

The researcher noticed that the site reflected the input of a parameter inside an input tag. A parameter is a named value you attach to a web address, usually after a question mark, for example ?param1=hello. The website reads that value and puts it into the page it sends back. An input tag is the HTML element that draws a text box on a page, and its value attribute holds the text that appears inside the box.

The reflection looked like this:

HTML
<input name="param1" value=$param1>

Line by line:

  • <input starts an input element, the text box.
  • name="param1" gives the box the name param1, so the site knows which field it is when the form is submitted.
  • value=$param1 is the important part. $param1 is a placeholder for whatever the visitor sent in the param1 parameter. The site drops that value straight into the page here, with no quotation marks around it.
  • > closes the tag.

The input is escaped correctly, so the tag cannot be closed early, and the characters > and < are completely blocked by the WAF. Escaping means turning characters that have a special meaning in HTML into harmless text, so that a < typed by a visitor is shown as a < on the page instead of starting a new tag. Blocking < and > on top of that makes it effectively impossible to spawn your own HTML tags, because every tag needs those angle brackets.

The detail that changes everything is that $param1 is not enclosed in any quotations. In HTML, an attribute value can be written with quotes or without them. Without quotes, the value ends at the first space. That means a space is enough to end the value and start a new attribute on the same input tag. The obvious next step is to add a space and use the onfocus event handler together with the autofocus attribute, so that the JavaScript runs as soon as a victim visits the link.

An event handler is an attribute whose value is code that the browser runs when something happens to the element, such as being clicked or receiving focus. Focus means the element is the one currently selected to receive typing, the way a text box gets a blinking cursor when you click it. autofocus is an attribute that tells the browser to give the element focus automatically when the page loads. Put together, onfocus plus autofocus means the code runs by itself the moment the page opens, with no click from the victim. In practice, the WAF stood in the way.

The WAF

The WAF performed two distinct actions:

  1. It completely blocked any request containing HTML, which included all event handlers such as onfocus.
  2. It stripped key JavaScript functions such as alert, prompt and console.log, and pretty much everything needed for an XSS proof of concept. It even stripped document.cookie.

A proof of concept, or PoC, is a small demonstration that a bug is real, usually the least harmful action that still proves code ran, such as showing a pop-up box. alert is the JavaScript function that opens such a pop-up. prompt asks the user for input in a pop-up. console.log prints a message to the browser's developer console, a hidden panel where programmers see errors and debug output. document.cookie is how JavaScript reads the cookies that belong to the current page.

A cookie is a small piece of data that a website asks the browser to store and send back with every later request to that site. Sites commonly use cookies to remember who you are after you log in, which is why reading them matters: a session cookie can let someone else act as you. Stripping means the filter deletes the matching text from the request before passing it on.

The author tried a lot of different handlers, and none of them were allowed. There was no magical way around the blocking of event handlers, and the write-up is explicit that this part was not bypassed.

Step 1: Understand what the WAF does

The two actions above are the whole picture of the WAF. It blocks HTML, so no event handler can get through in its normal form, and it deletes a list of JavaScript words, so even if a handler did get through, the code inside it would be broken. The author tried many handlers and none were allowed. This is the point where many testers give up, because both doors appear closed.

Step 2: Notice the order of the two filters

The solution lay in the application's additional security measures, namely the stripping of keywords such as alert and prompt. The key observation is about order. The WAF reads the request data before the web application ever gets its hands on it, so it can discard malicious requests safely. The application then strips the JavaScript keywords, and that happens afterwards.

Think of it as two checkpoints in a row. The first guard checks your bag against a list of forbidden items and lets you through if nothing matches. The second guard, further inside, removes certain items from the bag. If you can make an item look like something else to the first guard, it passes, and then the second guard's removal can turn it into the forbidden item after the first guard is no longer looking.

The idea was therefore to build a payload that the WAF would not block, but which, once the application had stripped those keywords, would become a working payload. A payload here just means the text you put into the parameter.

Step 3: Package the payload with alert

Since onfocus was blocked and alert and document.cookie were stripped, the author used alert as the packaging: it lets the payload pass the WAF safely and is then discarded by the application. The final payload was:

Text
 oalertnfocus=alalertert(documealertnt.cookie) autofocus

Line by line, reading it as one string:

  • It starts with a space. That space ends the unquoted value attribute and starts a new attribute.
  • oalertnfocus is the word onfocus with alert inserted in the middle. The WAF does not see the blocked word onfocus as such, because the letters are interrupted.
  • = separates the attribute name from its value.
  • alalertert is alert with another alert inserted in the middle, so the WAF does not see a plain alert.
  • (documealertnt.cookie) is document.cookie with alert inserted inside the word document, again hiding the blocked string.
  • autofocus adds the attribute that makes the browser focus the element automatically.

Each occurrence of alert is removed by the application's keyword stripping, and what remains is a valid attribute on the input tag. After the alert keyword is stripped, the full input element on the page becomes:

HTML
<input name="param1" value= onfocus=alert(document.cookie) autofocus>

Line by line:

  • <input name="param1" is the original input element, unchanged.
  • value= is now an empty value, because the space ended it.
  • onfocus=alert(document.cookie) is a new attribute on the same tag. Its value is code that reads the page's cookies and shows them in a pop-up.
  • autofocus makes the browser focus the element as soon as the page loads, which triggers onfocus without any action from the victim.
  • > closes the tag.

The leading space in the payload closes the unquoted value attribute, onfocus and autofocus are assembled from the fragments left after stripping, and the handler calls alert(document.cookie) when the input receives focus automatically. The payload was built so the WAF would not block it, and the application's stripping then produced a working payload.

Root cause

The mistake is the ordering and the nature of the two filters. The WAF blocks on the raw request, before the application processes it, while the application performs its own sanitisation afterwards. Sanitisation means cleaning input so it is safe to use. A payload that is harmless to the WAF can therefore be transformed by the application's stripping step into something dangerous.

The stripping is a blacklist of keywords rather than a structural defence. A blacklist names the things that are forbidden; a structural defence instead makes dangerous input impossible by construction, for example by encoding it so it can only ever be text. Removing substrings from attacker-controlled input can reassemble new tokens, which is exactly what happened here: deleting alert from oalertnfocus leaves onfocus.

The unquoted attribute value in the template is the second contributing factor: it allows a new attribute to be introduced with nothing more than a space. The write-up does not state how the application implemented the stripping.

Impact

The result is a reflected XSS: an attacker who gets a victim to visit a crafted link runs JavaScript in the victim's session on the affected site. Reflected means the malicious input comes back in the response to that same request, rather than being stored on the server. Running in the victim's session means the code runs as if it were the site's own code, with access to everything the page can see for that logged-in user.

The payload shown calls alert(document.cookie). The write-up does not describe any further actions, data or accounts affected, and it does not state which cookies were accessible or whether they were protected by other flags.

Fix

Based on the root cause, the fixes would be to quote the reflected value in the template, so that a space cannot introduce a new attribute, and to stop relying on keyword stripping as a security control, since removing substrings from attacker input can reassemble dangerous tokens. Context-aware output encoding of the parameter, applied by the application itself rather than only by the WAF, would remove the underlying reflection problem. Output encoding means converting the value into a form that is always treated as text in the place where it appears, so it cannot become markup or code.

Variants to test

  1. Unquoted attribute reflections: look for parameters echoed into value=$param without quotes. A positive result is that a space plus an attribute name appears as a new attribute in the rendered HTML.
  2. Filter ordering: send a payload containing a blocked keyword split by a benign token, such as alert inserted inside an attribute or function name, and check whether the application removes the token after the WAF has passed the request. A positive result is that the response contains the reassembled dangerous string.
  3. Keyword stripping of document.cookie: check whether the application removes it from input. A positive result is that the string disappears from the response while the surrounding payload survives.
  4. Event handler blocking: try onfocus with autofocus and other handlers. A positive result is that the handler is accepted and fires when the element receives focus.
  5. Character blocking: confirm whether < and > are blocked. A positive result is that they are rejected, which forces attribute-based payloads on an existing tag rather than new tags.

Glossary

  • Attribute: a named setting inside an HTML tag, such as value or autofocus, written as name=value.
  • autofocus: an HTML attribute that makes the browser focus an element automatically when the page loads.
  • Blacklist: a list of forbidden items that a filter checks against, as opposed to making dangerous input impossible.
  • Cookie: a small piece of data a site asks the browser to store and send back with later requests, often used to keep you logged in.
  • Cross-site scripting (XSS): a bug where a site runs code supplied by an attacker in another visitor's browser.
  • document.cookie: the JavaScript way to read the cookies belonging to the current page.
  • Escaping: converting characters with special meaning into harmless text so they are displayed rather than interpreted.
  • Event handler: an attribute whose value is code that runs when something happens to an element, such as receiving focus.
  • Focus: the state of being the element currently selected to receive input, like a text box with a blinking cursor.
  • GET parameter: a named value attached to a web address after a question mark, read by the site from the request.
  • HTML: the language that describes the structure of a web page, made of tags such as <input>.
  • Input tag: the HTML element that draws a text box on a page.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • onfocus: an event handler that runs code when an element receives focus.
  • Output encoding: converting a value into a form that is always treated as text where it appears, so it cannot become markup or code.
  • Parameter: a named value sent with a request, usually in the address or the body.
  • Payload: the text an attacker sends in a parameter to try to trigger a bug.
  • Proof of concept (PoC): a small demonstration that a bug is real, usually the least harmful action that still proves code ran.
  • Reflected XSS: XSS where the malicious input comes back in the response to the same request, rather than being stored on the server.
  • Reflection: a site copying input from a request back into the page it returns.
  • Sanitisation: cleaning input so it is safe to use.
  • Session: the state of being logged in on a site, usually tied to a cookie.
  • Stripping: a filter deleting matching text from input before passing it on.
  • Tag: an HTML building block written between angle brackets, such as <input>.
  • Token: a meaningful piece of text, such as a keyword or a name, that code or a filter recognises.
  • WAF (web application firewall): a filter that sits in front of a website and inspects requests before the application sees them.

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.