Skip to content
XSS Write-up Intermediate

DOM XSS On A Gov Domain Bypassing WAF

A search function reflected user input inside an existing script tag without filtering single quotes, allowing an attacker to break out of a string and inject JavaScript. A WAF blocked common alert functions, but the attacker bypassed it using an alternative way to call alert, achieving DOM-based XSS.

Tobydavenn Follow

Published on medium.com

Welcome back readers. I hope everyone is doing well.

Tobydavenn, 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. 5 min read.

Context

The author describes the application as looking outdated: it had plenty of content and features, but nothing about it looked modern, which is what drew attention to it as a likely source of vulnerabilities. The vulnerable feature was a search function. Each time a search was performed, a script was loaded into the DOM, and the search input was placed inside an already established script tag, within a var declaration.

Setup

The work was done from Kali Linux. The tooling was:

  1. A range of subdomain scanners to enumerate subdomains and produce a list readable on Kali.
  2. External quick-win XSS scripts run against the results. These missed the vulnerability described here, which the author uses to make the point about the importance of manually looking.
  3. Burp Suite Param Miner, used to collect all parameters and insert a unique canary into each one, then sift through the results to see exactly where the canary was reflected.
  4. DOM Invader in the Burp Suite browser, entering the same unique canary and searching each sink in which it appeared.

No accounts, roles or specific product versions are described.

Finding it

After collecting a few low-hanging findings, the author turned to XSS. Param Miner and DOM Invader both showed that the canary was reflected inside an existing script tag, within a var, as part of the search function. The reflected input looked like this:

HTML
<script> var ‘mycanary’ </script>

The script was called every time a search took place, so a payload placed there would be loaded into the DOM and executed. The application filtered ", <, > and /, but it did not filter '. That single quote was enough to close the string and start new code inside the script:

JavaScript
var ‘mycanary’ -alert(document.domain)-’

That attempt was blocked as well. A WAF was now in the way.

From the original on medium.com

Further testing showed that alert, confirm and prompt were all filtered. print() was not filtered, and using it confirmed the XSS, but the author wanted an alert box showing cookies for impact.

Exploitation

Step 1: Confirm the sink with a non-blocked function

With alert, confirm and prompt filtered by the WAF, print() was used to confirm that script execution was possible in the search context. This proved the DOM XSS but did not produce the alert box needed to demonstrate impact.

Step 2: Find an alert variant the WAF does not match

The author collected unusual ways of presenting an alert, drawn from other write-ups:

JavaScript
[%27al\x65rt%27](document.domain);//
window[‘alert’](0)
parent[‘alert’](1)
self[‘alert’](2)
top[‘alert’](3)
this[‘alert’](4)
frames[‘alert’](5)
content[‘alert’](6)
constructor.constructor(“aler”+”t(3)”)();
[].filter.constructor(‘ale’+’rt(4)’)();
top[“al”+”ert”](5);
top[8680439..toString(30)](7);
top[/al/.source+/ert/.source](8);
top[‘al\x65rt’](9);

These all reach the same function by a different route: bracket notation with a computed property name, string concatenation, a hexadecimal escape inside the string, a number converted to base 30, a regular expression's source, or the constructor chain. The WAF filtered the obvious function names, so forms that build the name at runtime were tried.

Step 3: Deliver the final payload

The ending payload was:

Text
foo%27-top[%27al\x65rt%27](document.domain);//

foo is the search term, %27 is the URL-encoded single quote that closes the var string, and -top[%27al\x65rt%27](document.domain);// is the injected code. top refers to the top-level window, and the property name is built with a hexadecimal escape (\x65 is e) so the literal string alert never appears in the request. document.domain is passed as the argument, and // comments out the remainder of the original script line. The author notes that URL encoding was not necessary on the '.

Root cause

The search input was written into an existing inline script tag inside a var string without escaping the single quote. The application's filter removed ", <, > and /, which prevents breaking out of the script tag or the string with a double quote, but leaves the single quote available to terminate the string and inject code. Because the value is placed into a script that runs on every search, the injected code executes in the DOM. The WAF added a second layer that blocked the obvious function names, and a computed property name got past it. The exact server-side code is not shown in the report, so the precise escaping mistake is likely a missing escape of ' in the string context.

Impact

The confirmed impact is script execution in the context of the government subdomain, demonstrated with an alert carrying document.domain. The author's stated goal was an alert box with cookies, which would allow session theft, but the report does not show that step being completed. The payload must survive the WAF, which the variant above does.

Fix

The report does not describe a fix or a vendor response. The appropriate change is to stop writing user input into an inline script string: escape the single quote and backslash for the JavaScript string context, or better, pass the search value through a safe API such as JSON.stringify or a data attribute rather than string concatenation. The WAF rule should also be reviewed, since blocking function names is bypassed by computed property names.

Variants to test

  1. Try a single quote in any parameter that lands inside a var string in an inline script. A positive result is a syntax error or a changed value in the DOM that shows the string was terminated.
  2. Try print() when alert, confirm and prompt are blocked. A positive result is the browser print dialog appearing.
  3. Try bracket notation with a computed name, such as top['al\x65rt'](document.domain), when the WAF matches alert. A positive result is the alert firing with the domain.
  4. Try the other forms from the list above, such as top[8680439..toString(30)](7) or top[/al/.source+/ert/.source](8), to see which ones the WAF misses.
From the original on medium.com

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

What happened, in plain words

A security researcher was looking around the internet for websites that might have mistakes in them. This is called reconnaissance, or recon: it is the same idea as walking around a building and checking which doors and windows are open before you try anything. During this walk-around, the researcher found a website run on a subdomain of a government domain. A subdomain is a smaller address that sits under a main one, like shop.example.com sitting under example.com. The researcher opened it in a browser and thought it looked old-fashioned: lots of pages and features, but nothing that looked recently built. Old-looking software is often a good place to look for mistakes, because it may not have been updated with modern protections.

On that site there was a search box. When you type something into the search box and press search, the site takes what you typed and puts it into a small piece of JavaScript, which is the programming language that browsers run to make pages interactive. The site put the search text inside a pair of quote marks in that script, like a name written on a label. The problem: the site did not handle one particular character, the single quote, safely. A single quote is exactly the character that ends a piece of text in JavaScript. So if you type a single quote into the search box, you can end the site's text early and start writing your own instructions. That is the whole idea behind a cross-site scripting bug, usually shortened to XSS: the site lets a visitor's input become code that the browser then runs.

The researcher built a payload, which just means the piece of text you send to exploit a bug. The first attempt was blocked by a WAF. A WAF, or web application firewall, is a filter that sits in front of a website and inspects incoming requests, blocking ones that look like attacks, a bit like a bouncer at a door checking names on a list. The WAF was blocking the obvious word alert, which is the JavaScript command that pops up a message box. The researcher then found a way to write the same command so the word alert never appears in the request. The browser still ran the alert, which proves the bug is real.

From the original on medium.com

The screenshot at the top of the write-up is the article's header image, shown before the researcher starts explaining the steps.

The setup: what tools were used and why

The researcher worked from Kali Linux, which is an operating system built for security testing. Think of it as a toolbox that comes with many testing programs already installed. The tools were:

  1. Subdomain scanners. These are programs that try lots of possible subdomain names and report which ones exist. The researcher used several of them and combined the results into one list that could be read on Kali. Why: you cannot test a website you do not know exists, and a big organisation often has many subdomains, some forgotten and less well maintained.
  2. External quick-win XSS scripts. These are automated programs that try common XSS tricks against a list of sites and report anything that looks promising. The researcher ran them here, but they missed this particular bug. The lesson the researcher draws is that automated scanners are not enough and a human still has to look manually. An automated scanner is like a spell-checker: useful, but it will not catch every mistake in a sentence.
  3. Burp Suite Param Miner. Burp Suite is a program that sits between your browser and a website so you can see and change every request and response. A request is what your browser sends to a server (for example, the search term you typed); a response is what the server sends back (the page). Param Miner is an add-on that guesses parameter names. A parameter is a named value sent with a request, like ?q=shoes where q is the parameter and shoes is its value. Param Miner collected all the parameters the site accepted, and the researcher put a unique canary into each one. A canary here means a distinctive made-up string, used like a labelled dye in water: you put it in and then look for where it comes out, so you know exactly which input reaches which part of the page.
  4. DOM Invader. This is a tool built into the Burp Suite browser. The DOM, or Document Object Model, is the browser's live in-memory model of the page: the browser reads the HTML the server sent and builds a tree of elements from it, and JavaScript can change that tree while you look at it. A sink is a place in the code where a value gets used in a way that can run code, such as writing into a script. DOM Invader lets you enter the same canary and then shows every sink where that canary turns up. Why: it tells you not just that your text appears on the page, but exactly which piece of code is handling it.

The report does not describe any accounts, user roles or specific software versions.

Finding the bug

After noting a few easy findings, the researcher focused on XSS. Param Miner and DOM Invader both showed the canary ending up inside an existing script tag, inside a var declaration, as part of the search function. A var is simply a way to declare a named variable in JavaScript, a labelled box that holds a value. The reflected input looked like this:

HTML
<script> var ‘mycanary’ </script>

Line by line: <script> opens a block of JavaScript that the browser will run. var ‘mycanary’ declares a variable whose name is the text mycanary wrapped in curly single quotes, and </script> closes the block. The important part is that the text the researcher typed is sitting between quote marks inside code the browser executes. The script was called every time a search happened, so anything placed there would be loaded into the page and run.

The site filtered ", <, > and /. Filtering means removing or rejecting certain characters. Those four characters matter because < and > are how you open and close HTML tags, " ends a double-quoted string, and / can close a tag. But the site did not filter ', the single quote. That was enough to close the string and start new code inside the script:

JavaScript
var ‘mycanary’ -alert(document.domain)-’

Line by line: var ‘mycanary’ is the site's own declaration. The ' after mycanary ends the string early. Then -alert(document.domain)- is new code the researcher added: alert opens a message box, and document.domain is the page's own domain name, passed in so the box shows which site the code is running on. The final ' is left over from the site's original closing quote. In plain terms, the researcher slipped extra instructions between the site's quote marks.

That attempt was blocked too. A WAF was now in the way.

From the original on medium.com

This image appears right after the researcher explains that the first payload was blocked and a WAF had to be dealt with.

Getting past the WAF

Further testing showed that alert, confirm and prompt were all filtered. All three are JavaScript commands that show a dialog box to the user, so blocking them is a common WAF tactic. print() was not filtered. print() tells the browser to open its print dialog. Using it confirmed the XSS: the print dialog appearing proved the researcher's code was running. But the researcher wanted an alert box showing cookies, because that is the classic way to demonstrate real impact.

A cookie is a small piece of data a website stores in your browser, and it is often used to remember that you are logged in. If an attacker can read a victim's cookie, they may be able to act as that victim. That is why an alert showing cookies is a convincing demonstration of impact, not just a harmless pop-up.

Step 1: Confirm the sink with a function the WAF does not block

With alert, confirm and prompt blocked, print() was used to confirm that script execution was possible in the search context. This proved the DOM XSS, meaning the bug where the browser's own page model runs attacker input, but it did not produce the alert box needed to show impact.

Step 2: Find an alert variant the WAF does not recognise

The researcher collected unusual ways of producing an alert, taken from other write-ups:

JavaScript
[%27al\x65rt%27](document.domain);//
window[‘alert’](0)
parent[‘alert’](1)
self[‘alert’](2)
top[‘alert’](3)
this[‘alert’](4)
frames[‘alert’](5)
content[‘alert’](6)
constructor.constructor(“aler”+”t(3)”)();
[].filter.constructor(‘ale’+’rt(4)’)();
top[“al”+”ert”](5);
top[8680439..toString(30)](7);
top[/al/.source+/ert/.source](8);
top[‘al\x65rt’](9);

Line by line, in plain words:

  • [%27al\x65rt%27](document.domain);// uses %27, which is the URL-encoded form of a single quote, and \x65, which is a hexadecimal escape meaning the letter e. Together they spell alert without the plain word appearing. The // starts a comment, so anything after it is ignored by the browser.
  • window[‘alert’](0), parent[‘alert’](1), self[‘alert’](2), top[‘alert’](3), this[‘alert’](4), frames[‘alert’](5) and content[‘alert’](6) all use bracket notation. In JavaScript you can reach a property either as object.alert or as object['alert']. The bracket form lets you build the name as a string, which a WAF matching the literal word alert may not spot. window, parent, self, top, this, frames and content are all references to browser windows or frames, which are separate browsing contexts inside a page.
  • constructor.constructor("aler"+"t(3)")(); reaches the constructor property, which in JavaScript can lead back to the Function constructor, a way to create a new function from a string. The string "aler"+"t(3)" is joined at runtime into alert(3), so the plain word is never sent.
  • [].filter.constructor(‘ale’+’rt(4)’)(); does the same trick through the constructor of the filter method on an empty array, again building the name from two pieces.
  • top["al"+"ert"](5); joins "al" and "ert" into alert at runtime.
  • top[8680439..toString(30)](7); converts the number 8680439 into base 30, a different way of writing numbers. The result is the string alert, so the property name is computed rather than written.
  • top[/al/.source+/ert/.source](8); uses a regular expression, a pattern for matching text. .source gives back the pattern as a plain string, so /al/ gives al and /ert/ gives ert, and joining them gives alert.

All of these reach the same function by a different route: bracket notation with a computed name, string concatenation, a hexadecimal escape, a number converted to base 30, a regular expression's source, or the constructor chain. The WAF filtered the obvious function names, so forms that build the name at runtime were tried. The everyday comparison: a bouncer with a list of banned names will stop someone called "Alert", but not someone who introduces themselves as "Al" and then "ert".

Step 3: Deliver the final payload

The ending payload was:

Text
foo%27-top[%27al\x65rt%27](document.domain);//

Line by line: foo is the search term the researcher typed. %27 is the URL-encoded single quote that closes the site's var string. Then -top[%27al\x65rt%27](document.domain);// is the injected code. top refers to the top-level browser window. The property name is built with a hexadecimal escape, where \x65 is e, so the literal string alert never appears in the request. document.domain is passed as the argument, so the alert shows the domain. // comments out the rest of the original script line, so the leftover quote from the site does not cause a syntax error. The researcher notes that URL encoding was not necessary on the '.

Why the bug exists

The search input was written into an existing inline script tag inside a var string without escaping the single quote. Escaping means marking a character so it is treated as ordinary text rather than as code. The site's filter removed ", <, > and /, which stops someone breaking out of the script tag or out of a double-quoted string, but it left the single quote available to end the string and inject code. Because the value is placed into a script that runs on every search, the injected code runs in the page. The WAF added a second layer that blocked the obvious function names, and a computed property name got past it. The report does not show the server-side code, so the exact escaping mistake is not visible; the likely cause is a missing escape of ' in the string context.

What the impact is

The confirmed impact is script execution in the context of the government subdomain, demonstrated with an alert carrying document.domain. The researcher's stated goal was an alert box with cookies, which would allow session theft, meaning stealing a logged-in session so the attacker can act as the victim. The payload must survive the WAF, which the variant above does.

How to fix it

The appropriate change is to stop writing user input into an inline script string: escape the single quote and backslash for the JavaScript string context, or better, pass the search value through a safe API such as JSON.stringify or a data attribute rather than string concatenation. An API here means a defined way for one piece of software to hand data to another, like a service counter with set rules, rather than pasting text directly into code. The WAF rule should also be reviewed, since blocking function names is bypassed by computed property names.

Variants to test

  1. Try a single quote in any parameter that lands inside a var string in an inline script. A positive result is a syntax error or a changed value in the page that shows the string was ended.
  2. Try print() when alert, confirm and prompt are blocked. A positive result is the browser print dialog appearing.
  3. Try bracket notation with a computed name, such as top['al\x65rt'](document.domain), when the WAF matches alert. A positive result is the alert firing with the domain.
  4. Try the other forms from the list above, such as top[8680439..toString(30)](7) or top[/al/.source+/ert/.source](8), to see which ones the WAF misses.

Glossary

  • API: a defined way for one piece of software to hand data or instructions to another, with agreed rules.
  • Burp Suite: a program that sits between your browser and a website so you can inspect and change requests and responses.
  • Canary: a unique made-up string inserted into input so you can trace exactly where it appears on the page.
  • Cookie: a small piece of data a website stores in your browser, often used to remember that you are logged in.
  • DOM (Document Object Model): the browser's live in-memory model of a page, built from the HTML and changeable by JavaScript.
  • DOM Invader: a tool in the Burp Suite browser that shows which sinks a canary reaches.
  • DOM XSS: a cross-site scripting bug where the browser's own page model runs attacker input.
  • Escaping: marking a character so it is treated as ordinary text rather than as code.
  • Filtering: removing or rejecting certain characters or values from input.
  • Hexadecimal escape: a way of writing a character in code using \x followed by its hexadecimal number, such as \x65 for e.
  • HTML: the language that describes the structure of a web page.
  • JavaScript: the programming language browsers run to make pages interactive.
  • Kali Linux: an operating system built for security testing, with many testing tools preinstalled.
  • Parameter: a named value sent with a request, such as ?q=shoes.
  • Param Miner: a Burp Suite add-on that guesses parameter names.
  • Payload: the piece of text sent to exploit a bug.
  • Recon (reconnaissance): the information-gathering phase, finding which sites and features exist before testing them.
  • Regular expression: a pattern for matching text, whose .source gives back the pattern as a plain string.
  • Request: what your browser sends to a server.
  • Response: what a server sends back to your browser.
  • Session theft: stealing a logged-in session so the attacker can act as the victim.
  • Sink: a place in code where a value is used in a way that can run code.
  • Subdomain: a smaller address under a main domain, such as shop.example.com under example.com.
  • URL encoding: writing special characters in a form safe for a web address, such as %27 for a single quote.
  • var: a JavaScript keyword that declares a named variable, a labelled box holding a value.
  • WAF (web application firewall): a filter in front of a website that inspects requests and blocks ones that look like attacks.
  • XSS (cross-site scripting): a bug where a site lets a visitor's input become code that the browser runs.

More by Tobydavenn

View all

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