Security Playground

Interactive Nuxt app showcasing real-world security vulnerabilities and their fixes.

Cross-Site Scripting (XSS)

Danger of rendering untrusted HTML.

Cross-Site Scripting (XSS) Demo

Learn about XSS vulnerabilities by testing malicious payloads in a safe environment. See the difference between vulnerable and secure implementations.

System Secure
0/500 characters

Vulnerable Rendering

LIVE DANGER
This renders user input directly with v-html - extremely dangerous!
Output will appear here...
Code: <div v-html="userInput"></div>

Safe Rendering

PROTECTED
This escapes HTML automatically with text interpolation {}
Output will appear here...
Code: <div>{}</div>

What is XSS?

Cross-Site Scripting allows attackers to inject malicious scripts into web pages viewed by other users.

Impact

XSS can steal cookies, hijack sessions, deface websites, or redirect users to malicious sites.

Prevention

Always escape user input, validate data, use CSP headers, and avoid innerHTML/v-html with user data.

Common XSS Payloads (Educational)
Basic Script Alert
<script>alert('XSS Success!')</script>

Most common XSS payload - shows a popup alert

Image with Error Handler
<img src='invalid' onerror='alert("Image XSS")'/>

Uses broken image to trigger JavaScript execution

SVG with onload
<svg onload='alert("SVG XSS")'></svg>

SVG element with JavaScript in onload attribute

Input with autofocus
<input onfocus='alert("Input XSS")' autofocus>

Auto-focusing input that triggers XSS immediately

Link with JavaScript
<a href='javascript:alert("Link XSS")'>Click me</a>

Link that executes JavaScript when clicked

See Fix

To prevent XSS, avoid rendering raw HTML with v-html. Use text interpolation or sanitize inputs with libraries like DOMPurify.

import DOMPurify from 'dompurify';
const sanitizedInput = DOMPurify.sanitize(userInput);
          

LocalStorage Misuse

Why storing sensitive data in localStorage is dangerous.

โš ๏ธ This form stores sensitive data insecurely in localStorage.
๐Ÿ‘ค
๐Ÿ”’

๐Ÿ”’ Safe Storage

โœ… Use HTTP-only cookies to store tokens securely, preventing client-side script access.
See Fix

Avoid storing sensitive data in localStorage, as any script can access it. Use HTTP-only cookies or server-side sessions.

// Backend (e.g., Express.js)
res.cookie('authToken', token, { httpOnly: true, secure: true });
          

Weak Hashing

Dangers of using weak hashing algorithms.

See Fix

Use strong hashing like bcrypt instead of MD5 or SHA-1.