XSS via the DOM

The JavaScript utility functions used on this page, in particular the URLSearchParams interface, might not work in all browsers: see the list of browsers that support it.

Go to this webpage with a parameter name in the URL, e.g.
http://www.cs.ru.nl/~erikpoll/websec/demo/xss_via_DOM.html?name=John.

The fragment of HTML below uses JavaScript in combination with the DOM to retrieve the parameter name from the URL to include include it in the content of the page. If you change the value of the parameter name, say from 'John' to 'Maria', the webpage show change.


Hello ! Welcome to this webpage.


You can now try to inject HTML mark-up tags, or even scripts, in the parameter name. For instance, try the links below:

Some things you can try:


The DOM-based cross-site scripting on this page is no real threat to our web server: you are simply injecting JavaScript that you are running client-side in your own browser. The script is sent to the server, but the server does nothing with it: the server just returns a fixed HTML page, and it is only when your browser renders this page, and executes the JavaScript inside, that the payload in the name parameter fires.

You could use this webpage to do a reflected XSS attack, by creating a link like the ones above and then tricking a victim into clicking that link. But there is no interesting data or functionality on www.cs.ru.nl for scripts to abuse: the domain does not set valuable cookies to steal and it does not offer any interesting functionality that such an attack could trigger.

Defences against reflected XSS that used to be built-in browsers, such as XSS Filter in Edge and XSS auditor in Chrome, would strip any scripts from a webpage that are identical to scripts passed as parameters in the URL. These defences have been retired in 2018 and 2019. (If you have a really old Edge or Chrome browser, you could try this out if it helps here.) These defences might stop some classic reflected XSS, but it would probably not stop this DOM-based XSS: after all, the script here is not included in the HTML page returned by the server; instead, only when the JavaScript code executes will the malicious scripts are inserted inside the webpage via the name parameter.


A typical DOM-based XXS injection will not be so simple as on this page. For this page the way that JavaScript can en up in the webpage, via the name parameter in the URL, is very straigforward. For most web pages that are vulnerable to DOM-based XSS the route by which malicious input can end up in the web page will be far more complicated.

The attacker's input may be passed back and forth between client and server and end up being HTML- or ULR-encoded, which may prevent input from being executed as script. In fact, for this page the name parameter in the URL is URL-encoded. Normally this would prevent it from being executed as script, as <script> URL-encodes to %3Cscript%3E. However, the JavaScript library function we use to retrieve the parameter values (the function get of the class URLSearchParams;check the source code of thi web page to see how that is done) is kind enough to automatically URL-decode data for us ;-)
If the JavaScript inside this webpage would (re-)URLencode the parameters before inserting them in the HTML then a simple DOM-based XSS is no longer possible. For instance, the URL-encoded name in the current URL displays as and this will not get executed as script by the browser.