Web security
Cross-Site Scripting (XSS) Explained for Beginners

Cross-site scripting, or XSS, lets an attacker run their own script in another user's browser, inside a trusted website. It is one of the most commonly reported web vulnerabilities in bug bounty programs. This guide explains the three types, why they matter and how they are fixed.
The Idea
A website shows text that came from a user: a search term, a comment, a profile name. If it inserts that text into the page without treating it as plain text, a browser may run it as code. Because the script runs on the real website, it can do anything that site's pages can do for the logged-in victim.
The Three Types
- Reflected XSS: the input comes from the request, for example a search parameter in a link, and is shown straight back. The attacker must get the victim to open a crafted link.
- Stored XSS: the input is saved, for example in a comment, and shown to everyone who views it. More dangerous, because it needs no special link.
- DOM-based XSS: the flaw is in the page's own JavaScript, which takes data from the URL or elsewhere and writes it into the page unsafely.
What an Attacker Can Do
- Act as the victim: change settings, send messages, make purchases
- Read data shown to the victim on that site
- Steal session tokens that are readable by scripts
- Show a fake login form on the real domain
How Testers Find It
Testers find every place user input appears in a page, work out the context (inside HTML, an attribute, JavaScript or a URL), and test whether characters that break out of that context survive. Burp Suite helps track where input is reflected. Proof of concept is kept harmless, such as showing an alert box, and only on authorized targets or labs like PortSwigger's Web Security Academy.
How Developers Prevent It
- Encode output for its context: HTML, attribute, JavaScript and URL contexts each need the right encoding
- Use frameworks that escape output by default, and avoid functions that bypass it
- Sanitize any user-supplied HTML with a maintained library
- Add a Content Security Policy to limit which scripts can run
- Mark session cookies HttpOnly so scripts cannot read them
Where It Sits in OWASP
XSS is part of the Injection category in the OWASP Top 10:2025, alongside SQL injection.
Learning Web Testing
Our Application Security course covers XSS and the other OWASP risks with Burp Suite in authorized labs, from finding a flaw to reporting it and checking the fix.
Want guided practice on web vulnerabilities? Book free trial classes. Contact us or call +91 86868 92922.
Where This Guide Fits in Our Training
- Web Application Penetration Testing Course in Hyderabad: the web application testing course and how it is taught
- API Security Training Online: REST, SOAP and GraphQL testing, with Burp Suite
- Cyber Security Course with Practical Labs in Hyderabad: how the labs work and what you practise in each class
Courses Mentioned in This Guide
More Guides
ffuf Commands for Beginners: Find Hidden Web Paths in a Lab
ffuf commands and cheat sheet: find directories and files, use filters and rate limits and read the results, with examples for a lab you own.
Read the guide →sqlmap for Beginners: Testing SQL Injection in a Lab
Learn sqlmap step by step: test a URL parameter, list databases and tables, use cookies and keep tests safe, with commands for a lab you own.
Read the guide →OWASP ZAP for Beginners: A Free Web Vulnerability Scanner
Learn OWASP ZAP step by step: proxy your browser, spider a site, run passive and active scans, read alerts and use the baseline script, in a lab you own.
Read the guide →SQL Injection Explained: How It Works and How to Prevent It
SQL injection in plain language: how it works, in-band and blind variants, real impact, how testers find it legally, and the fixes developers should use.
Read the guide →Start Your Cyber Security Career
Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.
- Call+91 86868 92922
Open 7 days: Mon to Fri 8:30 AM to 8:30 PM IST
Sat and Sun 10 AM to 6 PM IST - Emailinfo@hackingtrainer.com
- VisitGround Floor, G-3, Sri Venkatasai Nest, Kallu Compound Road, Nagarjuna Nagar Colony, Yella Reddy Guda, Ameerpet, Hyderabad – 500073
Open in Google Maps