
Cross-site scripting (XSS) lets an attacker run their own JavaScript in another user's browser, inside your website. It is one of the most common web vulnerabilities and appears in the OWASP Top 10 under Injection.
There are three main types: reflected (the payload comes from the current request), stored (the payload is saved and shown to every visitor) and DOM-based (the page's own JavaScript writes untrusted data into the page).
An application takes input, such as a search term, a comment or a URL parameter, and puts it into a page without encoding it. If the input contains HTML or script, the browser runs it as part of your site.
With reflected XSS the attacker sends a victim a crafted link. With stored XSS they post the payload once, for example in a profile field, and it runs for everyone who views that page. DOM-based XSS happens entirely in the browser, when code such as innerHTML or eval handles data from the URL.
innerHTML, document.write and eval; use textContent instead.HttpOnly so scripts cannot read them.innerHTML and eval usage.Reflected XSS comes from the current request, usually a crafted link, and affects the person who opens it. Stored XSS is saved by the application and runs for every user who views the affected page, so it usually has a wider impact.
A strict CSP greatly reduces the impact of XSS by blocking unauthorised scripts, but it is a second layer of defence. The fix is still to encode output and avoid unsafe JavaScript sinks.
Try Vooki Pro free for 7 days
Find XSS in your application before an attacker does, with the evidence your developers need to fix it. The trial unlocks every feature for 7 days, and scanning runs on your own machine.
Related: Blind SQL injection: how it works and how to stop it