|
| 1 | +<p align="center"> |
| 2 | + <a href="https://packagist.org/packages/roots/allow-svg"><img alt="Packagist Downloads" src="https://img.shields.io/packagist/dt/roots/allow-svg?label=downloads&colorB=2b3072&colorA=525ddc&style=flat-square"></a> |
| 3 | + <a href="https://github.com/roots/allow-svg/actions/workflows/tests.yml"><img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/roots/allow-svg/tests.yml?branch=main&logo=github&label=CI&style=flat-square"></a> |
| 4 | + < a href= "https://bsky.app/profile/roots.io">< img alt= "Follow roots.io on Bluesky" src= "https://img.shields.io/badge/[email protected]?logo=bluesky&style=flat-square"></ a> |
| 5 | +</p> |
| 6 | + |
| 7 | +# Allow SVG |
| 8 | + |
| 9 | +A WordPress plugin that enables SVG uploads with validation to block malicious files. |
| 10 | + |
| 11 | +> WordPress still lacks native SVG support after [12+ years of discussion](https://core.trac.wordpress.org/ticket/24251) |
| 12 | +
|
| 13 | +## Features |
| 14 | + |
| 15 | +- ✅ **SVG Upload Support** — Enables `.svg` uploads in the WordPress media library |
| 16 | +- 🔒 **Security-First Validation** — Detects and rejects SVG files containing potentially harmful content |
| 17 | +- 🖼️ **Media Library Integration** — SVGs display inline like standard images |
| 18 | +- 🧩 **Zero Dependencies** — No external libraries or frameworks |
| 19 | +- ⚙️ **Zero Configuration** — No settings or admin bloat |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +- PHP 8.2 or higher |
| 24 | +- WordPress 5.9 or higher |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +### via Composer |
| 29 | + |
| 30 | +```bash |
| 31 | +composer require roots/allow-svg |
| 32 | +``` |
| 33 | + |
| 34 | +<details> |
| 35 | +<summary>Install as a mu-plugin</summary> |
| 36 | + |
| 37 | +If you are using [Bedrock](https://roots.io/bedrock/), you can install this as a must-use plugin by modifying your `composer.json` to install the package to the `mu-plugins` directory. |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "extra": { |
| 42 | + "installer-paths": { |
| 43 | + "web/app/mu-plugins/{$name}/": [ |
| 44 | + "type:wordpress-muplugin", |
| 45 | + "roots/allow-svg" |
| 46 | + ] |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +</details> |
| 53 | + |
| 54 | +### Manual |
| 55 | + |
| 56 | +1. Download `allow-svg.php` |
| 57 | +2. Place in `wp-content/plugins/allow-svg/` |
| 58 | +3. Activate via wp-admin or WP-CLI |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | +Once activated, the plugin automatically: |
| 63 | + |
| 64 | +1. Enables SVG uploads through the Media Library or block editor |
| 65 | +2. Performs strict validation on all SVG files |
| 66 | +3. Rejects malicious files with clear error messages |
| 67 | +4. Accepts clean, standards-compliant SVGs as-is |
| 68 | + |
| 69 | +No configuration required. |
| 70 | + |
| 71 | +## Security |
| 72 | + |
| 73 | +This plugin uses a **deny-first approach**: it doesn't attempt to sanitize SVGs, it rejects files that appear unsafe. |
| 74 | + |
| 75 | +### Accepts: |
| 76 | + |
| 77 | +- Basic SVG shapes, paths, text, and inline styles |
| 78 | +- ViewBox and standard attributes |
| 79 | + |
| 80 | +### Rejects: |
| 81 | + |
| 82 | +- `<script>` tags or inline JavaScript |
| 83 | +- Event handlers like `onclick`, `onload`, etc. |
| 84 | +- External references (`href`, `xlink:href`, `iframe`, `object`, `embed`) |
| 85 | +- CSS expressions and `@import` rules |
| 86 | +- Data URLs containing script or HTML content |
| 87 | + |
| 88 | +### XML Hardening: |
| 89 | + |
| 90 | +- **XXE Protection** — Blocks `<!DOCTYPE>` and external entity declarations |
| 91 | +- **Entity Expansion Limits** — Rejects suspicious `&entity;` usage |
| 92 | +- Uses `DOMDocument` with external entities disabled |
| 93 | + |
| 94 | +## Sponsors |
| 95 | + |
| 96 | +Allow SVG is an open source project and completely free to use. If you've benefited from our projects and would like to support our future endeavors, [please consider sponsoring us](https://github.com/sponsors/roots). |
| 97 | + |
| 98 | +## Support |
| 99 | + |
| 100 | +- GitHub Issues: https://github.com/roots/allow-svg/issues |
| 101 | +- Roots Discourse: https://discourse.roots.io/ |
0 commit comments