NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist, #489 most downloaded on Packagist
An SVG sanitizer for PHP
Latest stable
1.1.1
Last release 1 months ago
20 Oct 2026
Release timing varies
gaps range from 8 days to 13 months
Rarely documented
notes for 4 of 51 stable releases
Nothing withdrawn
no release was ever pulled
11 years old
51 releases · first in 2015
Drag across the ruler to compare, or tap a release to open it.
This release fixes a bug that was new in 1.1.0. Everyone using 1.1.0 should upgrade.
This release fixes a bug that was new in 1.1.0. Everyone using 1.1.0 should upgrade.
It fixes this advisory:
sanitize() could throw on input that ends inside an unclosed tag.sanitize() no longer throws a ValueError on PHP 8, or raises a warning on
PHP 7, when the input ends inside a tag that is never closed. A single <
or a truncated upload was enough. It now returns false, as 1.0.0 did. This
bug was new in 1.1.0.sanitize() returns false and reports the error in
getXmlIssues().Full changelog: https://github.com/darylldoyle/svg-sanitizer/compare/1.1.0...1.1.1
This is a security release. Everyone using 1.0.0 or earlier should upgrade. The public API has not changed, but some input is now cleaned differently.…
Your coding agent can read these notes before it upgrades. Set up the MCP server →
This is a security release. Everyone using 1.0.0 or earlier should upgrade. The public API has not changed, but some input is now cleaned differently. See "Changed" below before you upgrade.
It fixes these advisories:
href after sanitizing.removeRemoteReferences(true).removeRemoteReferences(true) could be slow, and could
throw.<use> reference graph could take exponential time, and its limits could
be avoided.sanitize() could throw instead of returning false.Animation elements such as <animateTransform> can no longer change a link's
href after sanitizing. Any attributeName that targets an href is removed.
A document whose DTD would still reach the XML parser is now rejected. That
covers DTDs in encodings the pre-parse stripper cannot read, such as UTF-16,
and DOCTYPEs hidden inside other DOCTYPEs. An internal DTD in UTF-16 or UTF-32
input is now rejected before parsing, so older libxml can no longer expand
its entities first, even with setAllowHugeFiles(true).
Input that is unsafe to hand to the XML parser is rejected before parsing:
The parser also now runs with LIBXML_NONET.
The <use> limits (useThreshold(), setUseNestingLimit() and loop
detection) now measure the document a browser actually renders, both as XML
and when the output is inlined in an HTML page. They are applied after tags
and attributes are cleaned. They also now cover <use> elements that are
nested inside other elements, that carry their own id, or that point at a
duplicated id. They read references the way browsers do, including letter
case, namespaces, whitespace and percent-encoding. useThreshold() now
counts every <use> a reference renders, at every level of a chain, not
only the deepest ones.
Attributes that could hold a URL can no longer hold javascript:,
vbscript: or non-image data: URLs, in every configuration. When the output
is inlined in HTML, an <image> inside <title> or <desc> becomes an HTML
<img> that uses src and srcset. The check covers every attribute except
inert ones such as title, class and id, and data-* and aria-*, as
in DOMPurify.
removeRemoteReferences(true) now catches many more ways of writing a remote
URL, in attributes and in <style>. These include CSS escapes, comments,
line continuations and control characters inside URLs, backslashes in place
of slashes, and schemes with no slashes. It also covers image-set()
arguments and quoted strings, which closes the old gap for image() and
src(). The stripped CSS is checked once more the way a browser reads it.
Several inputs that took seconds of CPU, or over 100 MB of memory, now take milliseconds. Each affected part of the pipeline now scales roughly linearly with the input:
DOCTYPE<use> reference graphsanitize() no longer throws. Input it cannot process safely now returns
false. That includes input that is empty once PHP tags or the DOCTYPE are
removed, a root element that is not <svg>, and a failed regular expression.
With minify(true), whitespace is collapsed before the security checks run,
so minifying can no longer change a value that was already checked.
<use> limits. useThreshold() now counts every <use> a reference
renders: those inside plain groups, and those at every level of a chain.
Very large legitimate artwork, such as a halftone pattern with more than
1,000 nested copies, can lose the <use> elements that reference it. Raise
the limit with useThreshold() if you need to.
Duplicate ids. When an id appears more than once and a <use>
references it, the later elements lose their id. Browsers only ever
resolve the first one. Duplicates that no <use> references keep their id,
so CSS #id rules still apply.
Removed spellings. These are now removed, because an HTML parser turns them into live SVG when the output is inlined:
<use> written in another letter case, such as <USE><use> in another namespaceid written in another letter case, such as IDxlink:href outside the XLink namespaceSelf-references. An href on an element other than <use> no longer
counts as a self-reference.
Unsafe URLs. An attribute that starts with a javascript:, vbscript:
or non-image data: URL is removed, in every configuration. For srcset,
each candidate is checked. Local paths, http(s) URLs and data:image/…
URLs stay. Inert attributes (alt, class, for, id, label, name,
pattern, placeholder, role, summary, title, value, style,
xmlns), data-* and aria-* are not checked.
Rejected documents. sanitize() now returns false in these cases:
<svg> root in a namespace other than SVG. A root with no namespace
is still accepted.DOCTYPE are removed'0', which used to return '' as if it were empty input.
Only '' counts as empty input now.removeRemoteReferences(true). This option now removes more:
srcset attribute, because it is a list of URLsaria-label that
quotes a link<style> block when a remote reference would otherwise surviveNew issue messages. getXmlIssues() can now report:
Duplicate id '…'Remote reference removed from 'style'Document is emptyInternal DTD subset is not allowedNested DOCTYPE declarationToo many attributes on one elementUnsupported document encodingRoot element is not in the SVG namespaceThe CLI scanner therefore now reports a file whose only problem was remote
CSS in a <style> element.
Issue list. getXmlIssues() lists at most 1,000 issues. When there are
more, its last entry says how many were left out. Every call to sanitize()
now starts with an empty list, including a call with empty input.
\D800, now decodes to U+FFFD
instead of producing invalid UTF-8.Full changelog: https://github.com/darylldoyle/svg-sanitizer/compare/1.0.0...1.1.0
Fix PHP 8.0+ deprecation warning: 'libxml_disable_entity_loader()' by @DmytroMaslakov in https://github.com/darylldoyle/svg-sanitizer/pull/124
I thought it was time to release a 1.00 version so we can properly follow Semver. Here we go.
href and xlink:href coexist by @nlemoine in https://github.com/darylldoyle/svg-sanitizer/pull/123Full Changelog: https://github.com/darylldoyle/svg-sanitizer/compare/0.22.0...1.0.0
DOCTYPE/DTD from the input before parsing. This prevents custom
entity definitions (which can collide with HTML5 named character references,
e.g. <!ENTITY Tab "#"> resolving 	 to U+0009 once inlined into HTML)
and DTD-defaulted attributes from ever reaching the XML parser.removeRemoteReferences(true)
so previously-missed remote references are stripped.<style> content and style attributes
more thoroughly under removeRemoteReferences(true): CSS escapes and comments
are resolved before matching (so \75 rl(…) or @\69 mport "…" cannot hide),
escaped or whitespace-separated @import is handled, and the bare-string form
of image-set() / -webkit-image-set() is covered. This remains best-effort —
a regex-based stripper cannot see through every CSS construct (the bare-string
forms of image() / src() are not handled), so untrusted CSS should still be
isolated at the embedding boundary. Unclosed url( / image-set( (which a CSS
tokenizer closes implicitly and still fetches) are stripped too. Note: when a
<style> / style block contains a stripped remote reference, its CSS escapes
are normalised (decoded) in the output — semantically equivalent, but it
rewrites author escapes in that block.] inside a DTD comment or entity value can no longer
truncate the scan early and leave a DTD fragment behind. The DOCTYPE is now
removed correctly by construction.sanitize() returns false — instead of being
cleaned. Because the DTD is stripped before parsing, the entity reference
becomes undefined and libxml rejects the document (fail-safe). A PUBLIC
DOCTYPE with no entity references (e.g. a typical Illustrator/Inkscape
export) still sanitizes normally.removeRemoteReferences(true), remote
references are now detected and removed in more places — bare remote
href/src values, unquoted url(...) references, url(...) embedded among
other declarations in a style attribute, and remote @import/url(...)
inside <style> element text. Previously only a whole-value, quoted url(...)
was matched. Local (/path) and fragment (#id) references are still
preserved.Resolved an issue where attribute name case inconsistencies (e.g., xlink:Href instead of xlink:href) in XML processing could cause namespace lookups a
Resolved an issue where attribute name case inconsistencies (e.g., xlink:Href instead of xlink:href) in XML processing could cause namespace lookups and sanitisation to fail. Attribute names in both namespaced and non-namespaced contexts are now normalised to their expected lowercase form before processing. This ensures consistent sanitisation of xlink:href and other targeted attributes regardless of their original case.
Full Changelog: https://github.com/darylldoyle/svg-sanitizer/compare/0.21.0...0.22.0
Props @ohader and @realazizk
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
One column per quarter.