WordPress does not support SVG uploads natively — and naive SVG plugins are a well-known attack surface. SVG files are XML documents that can carry XSS payloads, XXE attacks, external resource injection, and embedded HTML. CodePros SVG Secure Support adds safe, production-ready SVG uploads through a layered defense pipeline.
Every uploaded SVG passes through five sequential checks before it is accepted:
payload.php.svg) and enforces .svg only.image/svg+xml via finfo; confirms <svg or <?xml is present in the header bytes.<svg> width/height/viewBox; rejects unreasonably large declared dimensions (default 10,000 px).After validation, the file is sanitized:
javascript:, <script, inline event handlers (on*=), and CSS expression() — any match causes the upload to be rejected entirely.When SVG attachment pages are served, the plugin adds:
Content-Security-Policy (configurable, secure default provided)X-Content-Type-Options: nosniffX-Frame-Options: SAMEORIGINThe plugin’s PHP layer covers every SVG upload that passes through WordPress. But if someone accesses an uploaded file directly — e.g. by visiting https://example.com/wp-content/uploads/2024/01/logo.svg — WordPress is bypassed entirely, so the PHP security headers are never sent.
The plugin ships two ready-to-use server configuration snippets to close that gap:
uploads-htaccess.txt — for Apache / LiteSpeed serversuploads-nginx.conf — for Nginx serversEach snippet does three things:
wp-content/uploads/ — if an attacker somehow uploads a .php file and tries to access it directly, the server returns 403 instead of executing it.image/svg+xml) — some server setups serve SVGs as text/plain, which prevents browsers from honouring Content Security Policy rules scoped to that MIME type.X-Content-Type-Options, X-Frame-Options, and Content-Security-Policy headers that the PHP layer adds on WordPress attachment pages, so direct file links are equally protected.Applying these snippets is the difference between WordPress-mediated access being protected and all access (direct URL, CDN pull, hotlink) being protected.
A tabbed settings page under Settings SVG Secure Support provides:
.htaccess and Nginx config snippets for the uploads directory