Test files › Images › svg-with-script.svg

SVG containing a script (XSS test)

SVG containing an inline <script> block and an onload attribute. The payload only calls console.log and sets document.title - it is inert and does not exfiltrate anything.

↓ Download svg-with-script.svg
Filenamesvg-with-script.svg
FormatSVG
Size457 bytes (457 bytes)
MIME typeimage/svg+xml
SHA-256cda5b1d93e5c72c74f1f3444232e2b52a927757aa6e240bcf724a0748408d623
What this file catchesThe single most commonly missed upload vulnerability: serving user-uploaded SVG from your own origin executes script in your security context. Your handler should either sanitise the markup or serve it with Content-Disposition: attachment and a restrictive CSP.

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

An SVG is a document that can run script, so an uploaded one is an XSS risk when served inline. This screen is triage, not a sanitiser: serve user SVGs from a separate domain with a strict Content-Security-Policy, or rasterise them.

import re

RISKS = [
    (r"<!ENTITY|<!DOCTYPE[^>]*\[", "declares entities (XXE)"),
    (r"<script\b", "contains <script>"),
    (r"\son[a-z]+\s*=", "has an on* event handler"),
    (r"(?:href|src)\s*=\s*[\"']?\s*javascript:", "links to javascript:"),
    (r"<foreignObject\b", "embeds HTML in foreignObject"),
    (r"(?:href|src)\s*=\s*[\"']?\s*https?://", "loads an external resource"),
]
with open("svg-with-script.svg", encoding="utf-8") as f:
    svg = f.read()
found = [label for pattern, label in RISKS if re.search(pattern, svg, re.I)]
print("unsafe to serve inline: " + ", ".join(found) if found else "no active content found")

Run against this file, it prints: unsafe to serve inline: contains <script>, has an on* event handler

Related guides and tools

Sample image filesFile signaturesMIME typesUpload validation checklistCheck a file's real typeVerify its SHA-256

Download & verify

curl -fsSL -o "svg-with-script.svg" "https://files.hexaqa.com/image/svg-with-script.svg"
curl -fsSL "https://files.hexaqa.com/image/svg-with-script.svg" | sha256sum # expect: cda5b1d93e5c72c74f1f3444232e2b52a927757aa6e240bcf724a0748408d623

More images test files

png-truncated.pngpng-valid-256.pngsvg-external-entity.svgsvg-plain.svgtiff-rgb-be.tiftiff-rgb-le.tiftransparent-1x1.webpbmp-24bit.bmp

← All Images files