Concrete examples of XSS: copy-paste code snippets
Below are classic non‑<script> XSS tricks that show why filtering <script> is useless. All examples use harmless alert() and are for education / labs.
1️⃣ <img src=x onerror=…> (the classic)
🧨 Payload
💡 Why it works
-
xis not a valid image -
onerrorfires automatically -
No
<script>tag involved
🔥 This bypasses tons of naive filters.
2️⃣ Mouse events (onmouseenter, onmouseover)
🧨 Payload
or
💡 Why attackers like this
-
Looks innocent
-
Doesn’t auto-execute
-
Works great in stored XSS (comments, profiles)
3️⃣ SVG-based XSS (very common bypass)
🧨 Payload
Or:
💡 Why it works
-
SVG is XML + JS
-
Many filters allow
<svg>but forget events
4️⃣ <iframe> injection
🧨 Payload
Or:
⚠️ Real-world note
srcdoc is often forgotten in sanitizers.
5️⃣ <details> + ontoggle
🧨 Payload
💡 Why this is sneaky
-
Rarely filtered
-
Executes when element opens
6️⃣ <input autofocus onfocus=…>
🧨 Payload
💥 What happens
-
Page loads
-
Input auto-focuses
-
onfocusfires instantly
No click needed 👀
7️⃣ <video> / <audio> events
🧨 Payload
or
8️⃣ <body onload> injection
🧨 Payload
Works if attacker can inject into page template.
9️⃣ javascript: URLs
🧨 Payload
Even sneakier:
🔟 Breaking out of attributes
Vulnerable HTML
🧨 Payload
💥 Result
1️⃣1️⃣ style attribute + CSS tricks (browser‑dependent)
🧨 Payload
⚠️ Less reliable today, but great teaching example.