JavaScript URL Schemes and Pseudo-Protocols
You'll learn how attackers abuse special URL schemes to execute JavaScript or inject content in href, src, and other URL-based attributes.
When browsers encounter URLs, they don't always fetch remote resources. Some special URL schemes—called pseudo-protocols—tell the browser to execute code or render data directly. Attackers exploit these to inject malicious scripts in contexts that expect "safe" links.
The Core Idea
Think of a URL like an instruction. http://example.com says "fetch this page from the web." But javascript:alert(1) says "execute this JavaScript code right now." If an attacker can inject these special schemes into clickable links or resource attributes, they can trigger XSS.
Common Attack Schemes
javascript: protocol executes JavaScript when clicked or loaded:
<a href="javascript:alert(document.cookie)">Click me</a>
data: URIs embed content directly, including executable scripts:
<iframe src="data:text/html,<script>alert(1)</script>"></iframe>
vbscript: protocol (Internet Explorer legacy) executes VBScript code:
<a href="vbscript:MsgBox(document.cookie)">Old IE attack</a>
Where They Hide
These schemes work in multiple contexts:
<a href="..."><iframe src="..."><img src="...">- CSS
url()properties - Form
actionattributes - Any user-controlled URL input
Why It's Dangerous
Even if you block <script> tags, these pseudo-protocols let attackers execute code through innocent-looking attributes. A stored javascript: link becomes a persistent XSS vector that triggers whenever someone clicks it.
Key Takeaway: Always validate and sanitize URLs against dangerous schemes like javascript:, data:, and vbscript: before rendering them in href, src, or any URL context—blocklisting <script> alone won't protect you.