SVG XSS
Cross-site scripting attacks that abuse SVG (Scalable Vector Graphics) elements, which can contain embedded JavaScript via event handlers or script tags.
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.
How It Works
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.
Prevention
- Sanitize SVG content, removing script tags and event handlers
- Serve uploaded SVGs with
Content-Type: image/svg+xmlandContent-Disposition: attachment - Use CSP to restrict script execution
- Consider converting SVG to PNG on upload