| 开发者 |
fatih-toprak
optimisthub |
|---|---|
| 更新时间 | 2026年10月5日 23:36 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
<script> elements and inline JavaScriptonload, onclick, onerrorjavascript: URLs in links and attributes<foreignObject> payloads<image>, <use>, href and xlink:hrefurl() and @import rules inside <style> blocksexpression() and behavior: declarationsenshrined/svg-sanitize library (0.22.0+)By default only administrators (users with the manage_options capability) can upload SVG files. Everyone else is blocked, because SVG is the one image format that can execute code.
You can change this with the optimisthub_svg_enabler_capability filter. For example, to let editors upload SVG as well:
add_filter( 'optimisthub_svg_enabler_capability', function ( $capability ) { return 'edit_others_posts'; } );
Return an empty string to allow anyone who can upload files.
Yes, this can be done using the optimisthub_svg_enabler_allowed_attributes and optimisthub_svg_enabler_allowed_tags filters. They take one argument that must be returned.
`
add_filter( 'optimisthub_svg_enabler_allowed_attributes', function ( $attributes )
{
$attributes[] = 'target'; // This would allow the target="" attribute.
return $attributes;
} );
add_filter( 'optimisthub_svg_enabler_allowed_tags', function ( $tags )
{
$tags[] = 'use'; // This would allow the element.
return $tags;
} );
`
The file either was not valid XML, did not contain an <svg> root element, or could not be sanitized. Rejected files are never stored. Try re-saving the file with a vector editor such as Inkscape or Illustrator.
It removes the known dangerous constructs from uploaded SVG files and keeps the sanitizer library up to date. No sanitizer can be considered a complete guarantee, which is why upload permission is restricted to administrators by default. Only upload SVG files from sources you trust.
Yes, .svgz files use the same MIME type and are sanitized the same way.
href, xlink:href, src and similar attributes are now removed. Previously an uploaded SVG could contact an external server.@import, remote url() references, expression() and behavior: inside <style> blocks are now removed.enshrined/svg-sanitize from 0.15.4 to 0.22.0. The old version was affected by CVE-2025-55166, CVE-2022-23638 and CVE-2019-10772.manage_options capability by default, instead of relying on unfiltered_upload, which WordPress only grants on multisite.svgFileValidator() called $this->sanitize(), a method that did not exist.svgFileValidator() for wp_check_filetype_and_ext with four accepted arguments while the callback only accepted one.wp_check_filetype_and_ext() from inside its own filter.$width and $height variables in getImageTagOverride() when $size was not an array.optimisthub_svg_enabler_allowed_attributes and _allowed_tags filters being applied but their return values discarded, which made both filters do nothing.width/height or viewBox.OptimistHub\SvgEnabler).composer.json so dependencies are reproducible; the previous composer.json was excluded by .gitignore.dom and libxml extensions, and shows an admin notice explaining why.