Project
XSS Playground
A simple fake social feed that shows reflected, stored, and DOM-based XSS in a safe browser-only demo. It also shows the small code change that stops each one.
Reflected XSS
Reflected XSS happens when untrusted input is returned to the page and executed immediately after the application reflects it back to the browser.
Stored XSS
Stored XSS happens when malicious input is saved by the application, such as in a post or comment, and then runs whenever users load that content later.
DOM XSS
DOM-based XSS happens in client-side JavaScript when the page reads unsafe data and writes it into the DOM in a way that allows code to run.
Type a normal search term below, or click one of the sample payloads to try it as XSS. If the page treated it like HTML instead of text, a payload could run as soon as the page renders it back.
div.innerHTML = userInput;
div.textContent = userInput;
Write a normal post below, or click one of the sample payloads to try it as XSS. If a bad payload were saved and shown back to everyone, every visitor could be affected.
post.innerHTML = savedPost;
post.textContent = savedPost;
Type a normal value below, or click one of the sample payloads to try it as XSS. This example copies a value from the fake URL hash into the page, so no server is needed for the problem to happen.
div.innerHTML = location.hash.slice(1);
div.textContent = location.hash.slice(1);
Use textContent
If you only need to show text, use textContent instead of innerHTML.
Use CSP
A content security policy can help block injected scripts if something slips through.
Sanitize carefully
If HTML really must be allowed, use a trusted sanitizer instead of trying to write your own.
This demo is a safe simulation. It does not run real attacker scripts or touch real cookies. The popup is there to show what would happen on a weak page.
How It Was Made
This project was built as a browser-only demo with plain HTML, CSS, and JavaScript. The goal was to make XSS easier to see without needing a backend or a real vulnerable site.
Q&A
textContent shows the text as text. It does not parse tags or attributes as real HTML.