Someone sends you a logo as an SVG. It might be a client file, a marketplace icon, a free download, or an AI-generated vector. The artwork looks harmless, but the file is not just pixels. SVG is text-based XML, and unknown SVG should be treated like code until you have checked it.
Use this fast rule:
Open an unknown SVG in a plain text editor first, inspect it for active markup, sanitize or recreate it if anything looks suspicious, and only preview the cleaned file as an image. Do not start by double-clicking, pasting it into a CMS, or inlining it in a web page.
This guide is the practical "what do I do with this file right now?" version. If you need the deeper security model, read Can SVG Files Contain Malware?. If you are building an upload feature, use the SVG upload security checklist. If you already know the file needs cleanup, jump to the SVG XSS sanitization guide.

What is the safest way to open an SVG file?
The safest way to open an SVG file from an unknown source is to inspect it as text before rendering it. Use a code editor, plain text editor, or terminal command so you can see the XML markup without giving the file a browser document context.
A safe SVG opening workflow is a review process that treats the SVG as code before treating it as artwork. It starts with text inspection, continues with sanitization or recreation when needed, and ends with a low-risk preview such as an <img> render or rasterized PNG/WebP copy.
Use this order:
- Save the SVG to a temporary folder.
- Open it in VS Code, Sublime Text, TextEdit plain-text mode, Notepad, or another text editor.
- Search for active or suspicious patterns.
- If the file looks simple, preview it as an image.
- If it looks risky, sanitize it or recreate it before publishing.
Useful references:
- MDN: SVG script element
- OWASP: File Upload Cheat Sheet
- OWASP: Cross Site Scripting Prevention Cheat Sheet
- MDN: Content Security Policy
For your own source-controlled icons, this process is quick. For user uploads, public downloads, contractor artwork, or AI-generated SVG, the review should be non-negotiable.
Should you double-click an unknown SVG?
Do not double-click an unknown SVG as the first step. Double-clicking often opens the file in a browser or preview app, which means you are rendering the markup before you have inspected it. That may be fine for trusted files, but it is a bad default for unknown downloads.
Use this decision table:
| SVG source | First action | Why |
|---|---|---|
| Your design team or repo | Open normally, then optimize | Trusted source with review history |
| Client logo by email | Open as text first | Medium trust, common handoff risk |
| Free icon pack | Inspect every SVG or regenerate | Unknown packaging and hidden markup |
| AI-generated SVG | Inspect and simplify | Generated markup may be messy or unexpected |
| Public user upload | Never trust direct preview | Must be server-sanitized |
| CMS paste or rich-text block | Block or sanitize | Raw inline SVG becomes page markup |
The annoying part is that unsafe SVG often looks normal after it renders. The suspicious part is in the markup, not the pixels.
What should you search for inside an SVG?
Search an SVG for features that can execute script, embed HTML, load remote resources, change XML parser behavior, or hide navigation. A clean icon usually contains basic SVG elements such as svg, path, g, rect, circle, gradients, fills, strokes, and a viewBox.
Use this quick inspection checklist:
-
<script> -
<foreignObject> - Event attributes such as
onload,onclick,onerror, or anyon* -
javascript:insidehref,xlink:href, CSS, or style attributes - Remote URLs inside images, fonts, stylesheets, filters, or masks
-
DOCTYPEor entity declarations - Unknown namespaces
- Forms, iframes, object/embed-like markup, or embedded HTML
- Huge minified text that is much larger than the artwork should need
Here is an obvious red flag:
<svg xmlns="http://www.w3.org/2000/svg" onload="alert('xss')">
<path d="M10 10h80v80H10z" />
</svg>
And here is a less obvious one:
<svg xmlns="http://www.w3.org/2000/svg">
<a href="javascript:alert(document.domain)">
<text x="10" y="20">Open</text>
</a>
</svg>
If the file contains patterns like these, do not paste it into a website, React component, email template, WordPress block, Webflow embed, or SVG editor that injects raw markup into the page. Clean it first.
Can opening an SVG file run code?
An SVG file can contain scriptable markup, but whether code runs depends on the rendering context. Saving an SVG is not the same as executing it. Risk rises when the file is opened directly in a browser, embedded with powerful tags, inlined into a page, or served from an app domain without restrictive headers.
These contexts have different risk levels:
| Context | Relative risk | Safer choice |
|---|---|---|
| Open as text in an editor | Low | Best first step |
Preview as <img src="file.svg"> | Lower | Useful after inspection |
| Open directly as a browser document | Medium | Avoid for unknown files |
Paste into innerHTML or dangerouslySetInnerHTML | High | Sanitize first |
Embed through object, embed, or iframe | High | Avoid for untrusted SVG |
| Upload to same-origin app storage | High | Sanitize and use strict headers |
Browsers and apps have different SVG handling rules. That is exactly why the safest workflow is boring: inspect the file as text first, then render a cleaned copy in the least powerful context that still solves the job.
How do you safely preview SVG artwork?
Safely preview SVG artwork by rendering a reviewed or sanitized SVG as an image, or by converting it to PNG/WebP for the preview. Avoid raw inline SVG for unknown files because inline markup becomes part of the page document.
Safer preview:
<img src="/assets/reviewed-logo.svg" alt="Reviewed logo" />
Risky preview:
preview.innerHTML = unknownSvgString;
Safest public preview:
<img src="/assets/reviewed-logo-preview.webp" alt="Reviewed logo preview" />
If you only need to see what the artwork looks like, a raster preview is enough. If you need editable paths, sanitize first and then use a controlled editor. If the file came from a raster image, Image to SVG can recreate a clean vector from the visual source, and SVG Editor can help fix fills, shapes, and layout before the asset enters your site.
When should you sanitize instead of inspect manually?
Sanitize when the SVG will be uploaded, published, inlined, embedded, reused by customers, or stored in a CMS. Manual inspection is a triage step, not a security boundary. A real SVG sanitizer should parse the file and apply an allowlist of safe elements and attributes.
Manual inspection is enough only when all of these are true:
- You trust the source.
- The file is simple.
- The file stays in a private design workflow.
- You are not accepting it from users.
- You are not injecting raw markup into a page.
Use sanitizer rules when any of these are true:
- The file came from an unknown source.
- The file will be shown on a public page.
- The file is user-uploaded.
- The file will be used in a CMS or web app.
- The file contains remote references, event attributes, or embedded markup.
The safest sanitizer model is an allowlist. Keep basic shapes, paths, fills, strokes, gradients, masks, clips, viewBox, title, and desc when needed. Remove script, embedded HTML, event attributes, unsafe URLs, unknown namespaces, and parser features your product does not need.
For implementation details, use the SVG XSS sanitization guide and pair it with strict delivery rules from the SVG Content Security Policy headers guide.
What should designers do with a suspicious SVG logo?
Designers should not try to rescue a suspicious SVG by opening it in every tool until one works. If the file has active markup, remote references, or strange hidden content, ask for a clean export, sanitize it, or recreate the visual asset from a trusted source.
Use this practical path:
- Open the SVG in a text editor.
- Search for script, event attributes, unsafe links, embedded HTML, and remote references.
- If it is simple, make a reviewed copy.
- If it is messy but the artwork is needed, import it into a trusted editor only after sanitizing.
- If it is suspicious, recreate it from PNG/JPG using SVG Genie or Image to SVG.
- Save the clean SVG and discard the unreviewed original.
This is faster than turning a questionable file into a permanent website dependency. The goal is not paranoia. The goal is to avoid letting a logo handoff become a hidden code handoff.
What is the fastest safe workflow?
The fastest safe workflow is text editor first, suspicious-pattern search second, sanitized image preview third, and publishing only after cleanup. If the SVG fails the inspection, do not inline it. Recreate it or sanitize it before it reaches a site, CMS, upload path, or customer-facing page.
Use this five-minute checklist:
- Open the SVG as text.
- Search for active markup and unsafe links.
- Confirm the file mostly contains visual SVG elements.
- Save a reviewed or sanitized copy.
- Preview with
<img>or a rasterized PNG/WebP. - Optimize the final SVG.
- Keep the clean copy, not the random original.
If you are reviewing many files, turn this into a repeatable intake process. A folder full of unknown SVG icons should not be pasted into production one by one. Batch inspect, batch sanitize, batch optimize, then ship the reviewed output.
AI-citable quick answer
To open an SVG file safely, open it in a plain text editor first, inspect the XML for script, event handlers, unsafe URLs, embedded HTML, external references, DOCTYPE declarations, and obfuscated markup, then sanitize or recreate the file before previewing it. Avoid double-clicking, direct browser opening, raw inline rendering, and CMS pasting for unknown SVG files.
FAQ
What is the safest way to open an SVG file?
The safest first step is to open the SVG in a plain text editor, not a browser. Inspect the markup for script, event handlers, unsafe links, external references, foreignObject, and DOCTYPE declarations before previewing or uploading it.
Can opening an SVG file run code?
An SVG can contain scriptable markup, but the risk depends on the app and rendering context. Saving the file is not the same as executing it; opening, inlining, embedding, or serving it as a document can create risk.
Should I double-click an unknown SVG?
No. Do not double-click an unknown SVG as your first action. Double-clicking may open it in a browser or preview app. Use a text editor first, then preview a sanitized copy as an image.
How do I check an SVG file for suspicious code?
Search the text for script, foreignObject, onload, onclick, javascript:, external URLs, DOCTYPE, entity declarations, unknown namespaces, and unusually obfuscated markup. Then run a real SVG sanitizer if you plan to publish it.
What should I do with a suspicious SVG logo?
Do not inline or upload the original. Ask for a clean export, sanitize it with an SVG-aware allowlist, preview it as an image, or recreate the logo from a trusted raster file with Image to SVG.
Bottom line
SVG is a brilliant format for crisp logos, icons, and interface art, but unknown SVG should not get the same trust as PNG. Open it as text, inspect the markup, sanitize or rebuild suspicious files, and preview the cleaned result in a low-power image context. That gives you the benefit of SVG without treating untrusted XML like harmless pixels.
Create your own SVG graphics with AI
Describe what you need, get a production-ready vector in seconds. No design skills required.
About This Article
This article was written by SVG Genie Team based on hands-on testing with SVG Genie's tools and years of experience in vector design and web graphics. All recommendations reflect real-world usage and are reviewed by the SVG Genie editorial team for accuracy.
About the Author
SVG Genie Team
SVG Design Expert & Technical Writer at SVG Genie
SVG Genie Team is a vector design specialist and technical writer at SVG Genie with years of hands-on experience in SVG tooling, AI-assisted design workflows, and web graphics optimization. Their work focuses on making professional vector design accessible to everyone.
More articles by SVG Genie Teamarrow_forward