Skip to content
Qlinnt
All guides

Practical security

SVG upload security: why an image can contain active content

By Qlinnt · Updated

SVG is structured content, not just pixels. For untrusted uploads, prefer rasterization when vector features are unnecessary, or use a maintained SVG sanitizer plus isolated serving. Test the actual embedding context; suspicious syntax alone does not confirm XSS.

Qlinnt conceptual illustration: SVG upload security: why an image can contain active content
Original Qlinnt illustration. A conceptual explanation, not an attack screenshot or evidence of exploitation.

Understand the problem before changing your site

A logo drawn with paths and a document containing script are both capable of using the SVG format. That does not mean every SVG is dangerous. The relevant questions are who supplied it, which transformations it passes through and how the browser embeds it.

Inline SVG, an image element, an object and a directly opened document have different execution rules. Namespaces, URL references and browser behavior complicate simplistic blocklists. An animation or use element alone is not proof of code execution, and a sanitizer passing one test is not a universal guarantee.

What to review and how to reduce risk

  • Separate trusted bundled illustrations from files uploaded by users. Define which features uploads actually require.
  • Prefer converting untrusted uploads to a raster format when the product needs only an image.
  • If SVG is necessary, use a maintained sanitizer and validate its output in the final rendering context.
  • Serve untrusted documents from an isolated origin without application cookies; review MIME type, Content-Disposition and CSP for that use.
  • Limit upload size and complexity, keep libraries updated and remove raw uploads from executable document paths.

How to verify it with safe tests

Build benign fixtures for paths, titles, gradients, internal use references, animation and ordinary external icon references. They should not become confirmed-XSS findings merely because the format supports active features.

Build separate synthetic fixtures with a script, an event handler or a javascript URL. Use a harmless local marker only in a controlled browser test. Compare inline and image embedding, record browser versions and distinguish a syntax observation from actual execution.

What Qlinnt can check and where its scope stops

Qlinnt's new check inspects inline SVG in the rendered DOM for script elements, event attributes and javascript links. It reports a review opportunity, retains signal categories rather than payload text and does not claim to validate a sanitizer.

External SVG response bodies, XML processing instructions and all browser-specific namespace behaviors are outside this first check. A clean inline result does not certify uploaded SVG files or every supported browser.

Should every SVG be removed?

No. Review provenance and embedding. Trusted static artwork is different from an arbitrary uploaded document.

Does finding an SVG script confirm XSS?

No. It establishes syntax in the observed DOM. Execution, attacker control and application impact require separate evidence.

Sources and further reading

Review your website's public surface

Scan a website you own or are authorized to assess. Verify your email to read the free diagnosis. The scan does not replace code tests or a specialist assessment.

Scan my website for free