Security Blog
Cross-Site Scripting (XSS) Explained: Types, Real-World Impact, and How to Find It
Cross-Site Scripting (XSS) has sat on the OWASP Top 10 for over two decades, and it is still one of the most commonly reported bugs in bug bounty programs today. If you are starting out in ethical hacking, XSS is usually the first "real" web vulnerability class you will learn to find and exploit — and understanding it properly pays off for the rest of your career, because the underlying idea (untrusted input ending up somewhere it can be interpreted as code) shows up again and again in other bug classes too.
What XSS Actually Is
XSS happens when an application takes input from a user and includes it in a page's output without properly neutralizing it first. If an attacker can get their own JavaScript to run inside another user's browser, in the context of the vulnerable site, they can do almost anything that user's session can do: steal cookies and session tokens, perform actions on the user's behalf, log keystrokes, redirect to phishing pages, or quietly modify the page the victim sees.
The key thing to internalize: XSS is not really a "JavaScript bug." It is an output-encoding bug. The application forgot to treat user input as data instead of code at the exact point where it got written into HTML, into a JavaScript context, into an HTML attribute, or into a URL.
The Three Types of XSS
1. Reflected XSS
The payload comes in through a request (commonly a URL parameter or form field) and is immediately reflected back in the response, with no persistence. A classic example is a search page that echoes the search term back onto the results page:
https://example.com/search?q=<script>alert(document.cookie)</script>
If that query string is rendered into the page without encoding, the script executes the moment the victim loads that exact URL. This is why reflected XSS is almost always delivered via a crafted link — a phishing email, a shortened URL, a malicious ad.
2. Stored XSS
The payload is saved on the server — in a database, a comment field, a user profile bio, a support ticket — and served back to every user who views that stored content later. Stored XSS is more dangerous than reflected XSS because the attacker does not need to trick a specific victim into clicking a link; anyone who views the affected page gets hit automatically. A comment section, a forum post, or a "display name" field that is not sanitized is a textbook stored XSS target.
3. DOM-Based XSS
This one does not even need the server to be vulnerable. The vulnerable code lives entirely in client-side JavaScript that takes some attacker-controllable value — often location.hash, document.URL, or window.name — and writes it unsafely into the DOM, commonly via innerHTML, document.write(), or eval(). Because the server never sees the payload (it's processed entirely client-side after the page loads), DOM XSS is frequently missed by traditional server-side input validation and even by some automated scanners.
Why This Still Matters in 2026
Modern frameworks like React, Vue, and Angular auto-escape output by default, which has genuinely reduced classic reflected/stored XSS in new applications. But XSS has not disappeared — it has moved. The common real-world causes today are:
- Developers deliberately bypassing framework escaping with
dangerouslySetInnerHTML(React),v-html(Vue), or[innerHTML](Angular) to render "rich" user content like markdown or HTML snippets - Legacy server-rendered templates (PHP, older JSP/ASP) that never had auto-escaping to begin with
- Client-side JavaScript that reads from the URL and writes to the DOM without sanitizing (DOM XSS)
- Rich-text editors and file upload features (SVG uploads are a classic XSS vector, since SVG is XML and can contain inline
<script>)
How to Start Finding It
The methodology is always the same three steps:
- Find every point where your input could end up in the response — search parameters, form fields, HTTP headers like User-Agent and Referer, file names, JSON fields that get rendered, even your own cookies if the app reflects them anywhere.
- Send a unique, harmless marker first (something like
xsstest123) and see exactly where and how it comes back in the response — inside an HTML tag body, inside an attribute, inside a<script>block, inside a JSON string that later gets parsed and rendered. - Craft a context-appropriate payload based on step 2. A payload that works inside an HTML tag body (
<script>alert(1)</script>) will not work inside an attribute (you'd need something like" onmouseover="alert(1)to break out of the attribute first), and neither will work inside an already-open<script>block (where you just need';alert(1);'or similar, no tags at all).
This is the single most important lesson for a beginner: there is no one universal XSS payload. The right payload depends entirely on the exact context your input lands in. Attackers (and good penetration testers) always confirm the context first, then craft the payload to fit.
Learn This Hands-On, Not Just in Theory
Reading about a vulnerability class is step one. Reproducing it yourself, in a safe lab environment, under guidance, is what actually turns it into a skill employers and bug bounty programs pay for. Rudra Tech Services runs hands-on ethical hacking and VAPT training out of Aurangabad (Chhatrapati Sambhajinagar), with real lab exercises covering exactly the vulnerability classes covered in this post.
If you want to practice this safely and legally, check out our Ethical Hacking course or try our recon-based CTF platform to test these techniques in a built-for-practice environment.
Explore RudraSec's Courses
Real hands-on training, with transparent pricing and no hidden placement claims.