Technical Articles

Review Cloudmersive's technical library.

Understanding SVG Files and the Dangers of XML Exploits
5/5/2025 - Brian O'Neill


Introduction

In this article, we’ll examine the security risks associated with Scalable Vector Graphics (SVG) file uploads, explore how attackers have used SVGs in real-world attacks, and highlight effective SVG-threat mitigation strategies with a focus on using Cloudmersive’s Advanced Virus Scan API.

The Appeal of SVG

Scalable Vector Graphics (SVG) files are a modern staple for websites and applications. They’re lightweight, resolution-independent, and easy to manipulate with code — all of which make them ideal for icons, logos, charts, and UI elements. Because SVGs are built on standard XML, they’re also easy for developers to generate and dynamically modify.

Not all developers share the same vision when it comes to modifying SVG content, however. Unfortunately, the same features that make SVG format so powerful also open it up to some of the most dangerous file-based vulnerabilities in modern web development.

Why SVG Files Are High-Risk

At first glance, SVG can seem similar ubiquitous binary file types like PNG and JPEG given their apparent overlap in everyday utility. Under the hood, however, SVG files are built quite differently: they’re designed as executable text rather than binary containers.

SVG files are full-blown XML documents, sharing more in common with Open Office formats like MS Word than other image formats like PNG or JPEG. SVG’s XML structure allows for all kinds of risky content to be embedded within the document, including complex threat injections.

drive by attack concept

SVGs can contain embedded JavaScript, remote resource references, event handlers (e.g., onload, onclick), inline CSS designed to manipulate document object model (DOM) behavior, animations and dynamic effects capable of triggering scripts or exploiting rendering behavior, and malicious XML payloads – like external entity declarations, for example – which can be used in XXE attacks to access local files, exfiltrate data, or perform denial-of-service exploits.

That’s a very wide attack surface for a file format that’s too often uploaded and displayed with minimal scrutiny. This makes SVG an excellent delivery vehicle for client-sides attacks, some of which include:

  1. Cross-Site Scripting (XSS): A SVG with embedded JavaScript triggers when the file is viewed in a browser, injecting code into the DOM
  2. Phishing: A SVG visually mimics a login screen or form, tricking users into giving an attacker sensitive information
  3. Clickjacking: An invisible or misleading click zone is created over web UI elements via SVG layering capabilities
  4. Drive-by Attacks: A user loading a malicious SVG (e.g., via image preview) triggers a payload embedded in the file structure

It’s important to emphasize that unlike many other similarly structured formats, SVGs don't need to be downloaded and opened to be dangerous. If a malicious SVG file is rendered in a browser — or even parsed on the backend — it may already be doing damage.

XXE: The Silent Threat Lurking in SVG

SVG’s XML foundation makes it especially effective in XXE (XML External Entity) attacks.

In an SVG-based XXE attack, an attacker crafts an SVG file containing a malicious XML declaration that references external entities (often file paths or URLs). When the file is parsed by a vulnerable XML processor – meaning one which hasn't been securely configured to disable entity expansion – it can leak passwords, application configuration files, and other sensitive information to an attacker, initiate network requests to sensitive internal resources (i.e., server-side request forgery), consume system resources, crash services, and – in extreme cases – execute arbitrary system commands.

These outcomes aren’t new concepts in the modern threat landscape, but many rendering libraries and platforms nevertheless continue to use unsafe default XML parsers – and that contributes to the overall elevated risks associated with SVG files. Malicious SVG uploads can trigger XXE attacks simply from being processed, even if the files in question are never viewed in a browser.

As apparently “harmless” visual assets, SVGs are often overlooked in standard threat models, and they’re too often allowed through perimeter filters or upload forms without the proper checks in place.

Real Examples of SVG Exploits

Some of the most high-profile cases of SVG-based attacks have been “drive-by” attacks, in which users simply opening and viewing a maliciously crafted SVG in a browser triggered a JavaScript payload.

In one attack campaign, threat actors uploaded SVG icons packed with malicious JavaScript which ran automatically when the images were rendered on a page. This allowed them to steal session cookies from victims or inject malicious scripts directly into their admin dashboards.

In another attack campaign, threat actors used SVG files to generate dynamic overlays which closely mimicked login prompts. This allowed them to harvest credentials in phishing-style attacks without ever leaving the victim’s browser.

credential spoofing concept svg article

The SVG files used in both these example campaigns were small and well-formed, which contributed to their bypassing antivirus (AV) and web application firewall (WAF) systems on route to execution.

Why Basic Scanning Doesn’t Catch It

SVG files can’t be treated like other image formats in an AV scanning workflow. This approach won’t reach deep enough into the file structure to identify the full scope of potential threats.

Most legacy AV solutions aren’t adequately equipped to parse and analyze XML structure, detect embedded script behavior, or identify XXE payload patterns within the file. They typically aren’t configured to understand the SVG event model (e.g., onload, script, animate tags) either.

Attackers can and do take advantage of weakly configured AV scanning using obfuscation techniques – such as base64-encoded payloads or nested object groups, for example – to hide malicious functionality within clean-looking files. Even simple event triggers like <svg onload="..."> can bypass naive scanning logic if the scanner doesn’t fully parse the document structure.

Protection against Malicious SVGs with Cloudmersive’s Advanced Virus Scan API

The Cloudmersive Advanced Virus Scan API treats SVG files as code, not just as images. It investigates each layer of SVG file structure in the same way it unpacks complex XML-based file types like DOCX, XLSX, PPTX, and others. Key defenses include:

  1. Parsing the entire XML structure of the file
  2. Blocking or flagging embedded JavaScript or scripting behavior
  3. Detecting and neutralizing XXE payloads
  4. Preventing remote resource calls and DOM-based exploits
  5. Analyzing obfuscated code patterns and event handlers

cloud security svg article

The Advanced Scan API also includes traditional signature scanning and heuristic analysis, making it capable of catching both known and novel (zero-day) SVG-based attacks. It acts before the file is displayed or parsed by any part of your system, reducing exposure windows and neutralizing threats at the point of upload.

Final Thoughts

SVGs are not just images. They’re code, and code should always be scanned.

They’re fast, flexible, and often underestimated. Their XML foundation, executable capabilities, and trusted status as a common image format make them uniquely attractive to threat actors.

If your system allows SVG uploads without inspecting them for embedded code or malicious structure, you may already be exposed. The Cloudmersive Virus Scan API helps you close that gap — by treating SVGs with the same caution you’d apply to any complex XML-based executable file.

If you’d like to learn more about protecting your system from malicious SVGs with Cloudmersive, please feel free to contact a member of our team.

800 free API calls/month, with no expiration

Get started now! or Sign in with Google

Questions? We'll be your guide.

Contact Sales