What is XSS?
Cross-Site Scripting (XSS) is a web vulnerability that allows attackers to inject malicious JavaScript into webpages viewed by other users. It’s one of the most reported bugs in bug bounty programs and consistently ranks in the OWASP Top 10.
Why Should You Care?
If your app is vulnerable to XSS:
-
🔓 Hackers can steal cookies and hijack sessions
-
💬 Inject fake login forms (phishing)
-
🎠Perform actions on behalf of users (CSRF chaining)
-
🧠Deliver payloads for malware or keyloggers
-
💣 Deface pages or spread worms (like the Samy worm)
Types of XSS (with Practical Demos)
1. ✅ Reflected XSS (Non-Persistent)
This happens when unsanitized user input is reflected in the response.
🔧 Vulnerable Example (PHP):
🧨 Exploit URL:
💡 Tip:
Try bypassing filters with:
2. ✅ Stored XSS (Persistent)
Malicious payload is stored in the database and triggered every time a user views it.
🔧 Vulnerable Example (Node.js + Express + MongoDB):
🧨 Exploit Payload:
💥 Once stored, it executes for every visitor to the page.
3. ✅ DOM-Based XSS
Manipulation happens in the frontend JavaScript itself.
🔧 Vulnerable HTML:
🧨 Exploit URL:
Defense Strategies (With Real Code)
🔒 1. Output Encoding
Use encoding libraries or frameworks that auto-escape output.
Example: Django
Example: React
2. Avoid Dangerous APIs
Never use:
Instead use:
3. Sanitize HTML (If Needed)
Use trusted libraries:
✅ DOMPurify (Browser)
✅ Node.js
4. Set a Strict Content Security Policy (CSP)
Blocks inline scripts and external injections.
5. Secure Cookies
Prevents JavaScript access and mitigates CSRF chaining.
💼 Real-World Bug Bounty Scenario
🎯 Target: https://target.com/profile?user=
Goal:
Inject a script via the user
parameter.
Steps:
-
Send this:
-
If reflected, it’s vulnerable.
-
Test
document.cookie
, DOM manipulation, CSP behavior, etc. -
Escalate by:
-
Stealing cookies
-
CSRF auto-actions
-
Fake login popups
-
👨💻 Practice Labs
🧪 Free Practice Platforms:
-
🎯 XSS Game by Google
-
💣 HackTheBox
-
🧠Root Me - XSS
0 Comments