| 开发者 | codeprosai |
|---|---|
| 更新时间 | 2026年6月15日 17:55 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.0 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
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).javascript:, <script, inline event handlers (on*=), and CSS expression() — any match causes the upload to be rejected entirely.Content-Security-Policy (configurable, secure default provided)X-Content-Type-Options: nosniffX-Frame-Options: SAMEORIGINhttps://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 serverswp-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..htaccess and Nginx config snippets for the uploads directorysvg-secure-support folder to /wp-content/plugins/.composer installvendor/autoload.php is missing.
Uploading via the WordPress Admin
After activation, simply upload .svg files through the standard WordPress Media Library. Users without the required capability will receive a clear error message.By default, only Administrators. You can grant access to one or more additional roles (Editor, Author, Contributor, Subscriber, or any custom role) under Settings → SVG Secure Support → Roles Allowed to Upload SVGs. If no roles are selected, only Administrators can upload. All role checks are performed at upload time.
The plugin implements every layer recommended by security researchers: validation → DOM sanitization with a strict tag/attribute whitelist → string-level payload scan → Content Security Policy headers. No sanitization approach can offer an absolute guarantee, but this multi-layer pipeline eliminates all known SVG attack vectors.
It depends on where the threat is detected:
javascript: survives DOM traversal) — upload is blocked entirely.The validation and sanitization pipeline runs only during file uploads, not on page loads. There is no frontend performance impact. The security headers are lightweight HTTP headers added on SVG attachment pages only (except X-Content-Type-Options: nosniff, which is sent on all pages).
It is strongly recommended. Without the server-level snippets, only requests routed through WordPress are protected. A direct URL to an uploaded SVG bypasses all PHP-layer security headers.
Apache — applying uploads-htaccess.txt
wp-content/uploads/.htaccess on your server.uploads-htaccess.txt (found in the plugin directory) and append them to that file..htaccess changes immediately — no restart needed.uploads/.htaccess when you save Permalink settings. Re-apply the snippet after that happens, or add the directives to your main Apache VirtualHost block so they cannot be overwritten.mod_headers to be enabled on your Apache installation (most managed hosts have it). The snippet also uses mod_mime, which is enabled by default.
Nginx — applying uploads-nginx.conf
/etc/nginx/sites-available/<your-site>.conf. In Local by Flywheel the per-site config is at ~/Local Sites/<site-name>/conf/nginx/site.conf.hbs.location blocks from uploads-nginx.conf and paste them inside the server {} block, before the generic location / block.sudo nginx -s reload (or restart the site from the Local app)..svg | No CSP, no X-Frame-Options | Full security headers applied |
| Direct URL to uploaded .php disguised as SVG | PHP executes (server-dependent) | 403 Forbidden |
| WordPress attachment page for an SVG | Protected by plugin PHP headers | Protected by both PHP and server headers |
| SVG served via CDN pull / hotlink | No headers | Server headers applied before CDN caches the response |
The following event types are recorded:
upload_allowed — SVG passed all checksupload_sanitized — SVG was cleaned before being savedupload_blocked — SVG was rejectedtag_removed — A disallowed tag was strippedattribute_removed — A disallowed attribute was strippedsuspicious_payload — A javascript: or similar payload was detectedGo to Settings → SVG Secure Support and click the Security Logs tab. You can filter by severity (Info / Warning / Critical) and event type, and purge entries older than the configured retention period.
The plugin has not been tested on WordPress Multisite. Network-wide activation is not currently supported.