Understanding cross-site scripting attacks and their impact
Learning Objectives
Understand what XSS is and its types
Learn how XSS attacks work
Understand the impact of XSS vulnerabilities
Identify XSS in web applications
When Websites Talk to Themselves (And They Shouldn't)
Picture this: you visit a website, and somehow that website runs code that wasn't supposed to be there. Maybe it steals your login session. Maybe it shows you a fake login page. Maybe it makes your browser do things you never asked for. That's Cross-Site Scripting, or XSS - one of the most common and misunderstood web vulnerabilities.
The name "Cross-Site Scripting" is actually terrible and confusing (it was named in the late 90s, give them a break). A better name would be "JavaScript Injection" because that's exactly what it is: injecting malicious JavaScript that runs in other users' browsers.
XSS has been in the OWASP Top 10 since forever. Despite being well understood, it remains extremely common because JavaScript is everywhere and escaping user input correctly is surprisingly hard.
XSS attacks run in the victim's browser, with their session, their cookies, their permissions. Always test responsibly and only on applications you own or have permission to test.
How XSS Actually Works
XSS happens when an application takes user input and puts it into a web page without properly sanitizing it. If the input contains JavaScript code, the browser happily executes it - because from the browser's perspective, it's just part of the page.
The Simplest Example
Imagine a search page that displays what you searched for:
html
1<!-- User searches for 606070;">#a5d6ff;">"laptops" -->
A website has a search feature. When you search for "test", the page shows:
<h2>You searched for: test</h2>
The input is being reflected directly in the HTML body without encoding.
Write a payload that would execute JavaScript.
Break Out of the Attribute
Challenge
🌱 easy
A search page puts your input inside an input field:
<input type="text" name="search" value="[YOUR_INPUT]">
The developers filter <script> tags but allow other HTML.
Write a payload that executes JavaScript.
Need a hint? (4 available)
No Script, No Problem
Challenge
🔥 medium
A website filters the following:
- <script> and </script> tags
- The word "javascript"
- onclick, onload, onerror
Your input appears in the page body:
<div class="content">[YOUR_INPUT]</div>
Find a way to execute JavaScript despite these filters.
Need a hint? (4 available)
JavaScript Context Escape
Challenge
💀 hard
Your input ends up inside a JavaScript string:
<script>
var searchQuery = "[YOUR_INPUT]";
console.log("User searched for: " + searchQuery);
</script>
The developers escape single quotes but NOT double quotes or backslashes.
Write a payload that executes alert(1).
Need a hint? (4 available)
XSS Fundamentals Quiz
Question 1 of 5
What does XSS stand for?
Key Takeaways
XSS lets attackers run JavaScript in victims' browsers
Three types: Reflected (in URL), Stored (in database), DOM-based (client-side)
Context matters: payloads differ based on where input appears in HTML
Many payloads exist: script tags, event handlers, javascript: protocol
Real attacks steal cookies, hijack sessions, or display fake content
Prevention: encode output, use Content Security Policy, validate input