JavaScript Protocol and Data URIs
You'll learn how attackers bypass XSS filters by embedding malicious code in special URI schemes instead of using obvious <script> tags.
The Core Idea
When XSS filters block traditional payloads like <script>alert(1)</script>, attackers turn to alternative ways of executing JavaScript. Two powerful techniques are javascript: pseudo-protocol and data: URIs—both allow code execution through URL-like mechanisms that many filters overlook.
How They Work
JavaScript Protocol:
The javascript: pseudo-protocol treats the URL as executable code. Instead of loading a page, the browser runs the JavaScript that follows:
<a href="javascript:alert('XSS')">Click me</a>
<img src="x" onerror="location='javascript:alert(1)'">
Think of it like a secret command prefix—when the browser sees javascript:, it knows to run rather than fetch.
Data URIs:
The data: scheme embeds content directly in the URL itself. You can embed HTML containing JavaScript:
<iframe src="data:text/html,<script>alert('XSS')</script>"></iframe>
<object data="data:text/html,<script>alert(1)</script>"></object>
It's like hiding your attack inside the URL rather than linking to an external resource. Base64 encoding adds another obfuscation layer:
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4="></iframe>
Why This Matters
These techniques slip past filters that only check for obvious tags or attributes. The code loads through legitimate browser features, making detection harder.
Key Takeaway:
javascript: and data: URI schemes allow XSS attacks to execute code through URLs instead of traditional HTML injection points, bypassing many basic content filters.