In this post, we are going to solve the PortSwigger lab: “Reflected XSS into HTML context with nothing encoded”.

To solve the lab, we need to perform a Cross-site Scripting attack that calls the alert function.
When we enter the lab, we see a search field:

Let’s try searching for anything:


If we look closely, the search term is reflected on the website. Therefore, we can try to inject JavaScript code using the onerror attribute in the <img> tag.
This way, if it fails to load the image we specify in the src attribute, it will execute what we write in onerror:


As we can see, it indeed failed to load the image, therefore the alert is executed. This way, we successfully solve the lab.