PortSwigger
Cross Site Scripting (XSS)
PortSwigger
LAB 1 (Reflected XSS into HTML context with nothing encoded)
Analysis
- Lab contains reflected XSS
- To solve, we need to execute the
alertfunction
Steps to solve
- After accessing the lab, I found a search input that displays what I write on the screen.
- Executed basic payload:
<img src=x onerror=alert(0)>→ success
Finished.. Happy hacking!
LAB 2 (Stored XSS into HTML context with nothing encoded)
Analysis
- Lab contains stored XSS
- To solve, we need to execute the
alertfunction
Steps to solve
- Searched the lab for input fields; after clicking “view post”, found a full comment form.
- Posted a comment with special words to test how the browser handles it.
- It appeared in the commenter’s name and comment body.
- Executed basic payload in both comment and name fields:
<img src=x onerror=alert(0)>→ success
Finished.. Happy hacking!
LAB 3 (DOM XSS in document.write sink using source location.search)
Analysis
- Lab contains DOM-based XSS in the search query.
- To solve, we need to execute the
alertfunction.
Steps to solve
- Inspected the JavaScript code; after searching, found the search term inserted into an
img srcviadocument.write.
- To make the alert work, injected:
"><img src=x onerror=alert(0)>
(closing the attribute and adding the payload)
Finished.. Happy hacking!
LAB 4 (DOM XSS in innerHTML sink using source location.search)
Analysis
- Lab contains a DOM-based XSS vulnerability in the search blog functionality.
- Content is added to the page using
innerHTML.
Steps to solve
- Viewed the page source and found the JavaScript code that processes the search query.
- It calls the function
doSearchQuery()which inserts findings viainnerHTML. - Injected into the search query:
<svg onload=alert('t4t4r1s')>→ alert popped up.
Finished.. Happy hacking!
LAB 5 (DOM XSS in jQuery anchor href attribute sink using location.search source)
Analysis
- DOM-based XSS on the feedback page.
- Goal: execute
alert(document.cookie).
Steps to solve
- Analyzed the page and found the
returnPathparameter controls the redirect path after submitting feedback. - Inserted a test string into the parameter and inspected the href of the “Back” link:
<a id="backLink" href="/ds">Back</a> - Tried injecting into the form itself → not vulnerable.
- Set the
returnPathparameter to:
javascript:alert(document.cookie)
→ the link executed the JavaScript when clicked → lab solved.
Finished.. Happy hacking!
This post is licensed under CC BY 4.0 by the author.






