DOM XSS in document.write sink using source location.search
https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-document-write-sink
Let's insert the following payload in the search field:
We can now open the developer tools and search our payload.
We can see that our payload has been inserted in the <img>
tag more specifically, it has been appended to the source of the image.
Right above that we can see a <script>
tag which includes the script responsible for the DOM manipulation:
The
trackSearch()
function takes aquery
parameter and writes an image tag to the document, where thesrc
attribute includes the search terms.The
query
variable is then assigned the value of the 'search' parameter from the URL usingURLSearchParams
.If the 'search' parameter exists in the URL, the
trackSearch()
function is called with the obtained query.
Now that we know how the DOM manipulation works, we can insert our final payload into the application which will generate an alert.
We have solved the lab.
Last updated