Changelog
phil/svg-sanitizerPas encore traduite
Cette page n’est pas encore traduite en français ; elle est montrée en anglais.
All notable changes to phil/svg-sanitizer will be documented in this file.
Updates should follow the Keep a CHANGELOG principles.
0.1.0-alpha - 2026-11-11
Added
SvgSanitizer:sanitize()reads an image as XML without network, document type nor entities, and writes anew, in the SVG namespace and without XML declaration, the elements and attributes the policy keeps, their text, and nothing else; returnsSanitized— the SVG, empty when the image is refused whole — and eachRemovalwith itsRemovalReason, subject and line, the firstSanitized::MAX_REMOVALS(100) listed and the others counted inomittedRemovals. An image is read in UTF-8 only: one with a null byte, as UTF-16 and UTF-32 have, or with bytes that are not UTF-8 is refused as malformed.Policy: allow lists of elements and attributes for static drawings — structure, shapes, text, paint servers, clipping, masks, markers, filters, raster images —, SMIL animation bywithAnimations(), the schemes of links, raster images indata:addresses, the CSS policy of the image, limits of size, depth, number of elements and attributes per element (maxAttributes, 256 by default, counted in one pass before the image is parsed, refused whole asTooManyAttributes); safe inline by default:<style>left out unlesswithStyleElements(true),new Policy(styleElements: true)orwithElements('style')allows it, and everyid, with every fragment ofhref,xlink:hrefandurl()that points to one, written afterwithIdPrefix()'s prefix,svg-by default,nullto keep them as written; the elements that run code or embed a document (script,foreignObject,iframe,object,embed…), event handlers,xml:baseand links tojavascript:,data:and their kind can never be allowed (InvalidPolicy).- References checked:
hrefandxlink:hrefto a fragment of the image; a PNG, JPEG, GIF, WebP or AVIF image in adata:address on<image>and<feImage>; a link of an allowed scheme on<a>, the whitespace and control characters of its scheme ignored as browsers ignore them. - CSS through
phil/css-sanitizer:styleattributes as declarations, allowed<style>elements as style sheets held inside the image — every rule placed under an id written from the image's content (the prefix,drawing-and sixteen hexadecimal digits of its SHA-256), which replaces the root'sid, every reference to it rewritten, so that two images on one page whose roots share anidnever share a rule, a selector that already starts with thatidkept as the image wrote it when it reaches nothing but the root and what lies inside it, the ids of selectors prefixed,@import,@page,@font-faceand every URL but a fragment removed —, and the presentation attributes and transform lists that hold more than names, numbers and colours as the value of their property, everyurl()but a fragment refused. - Animations that target a reference, a style or an event handler, and values of animation that hold a function or a scheme, removed.
- Processing instructions removed and reported; comments and document types left out.
SvgSanitizerException, implemented byInvalidPolicy.Validator\SafeSvg, asymfony/validatorconstraint, andSafeSvgValidator: each removal of the sanitizer a violation,NOT_ALLOWED_ERROR, and an image refused whole one violation,REFUSED_ERROR, with the reason, subject and line as parameters; the removals past the first 100 one more violation,moreMessage, with their count;nulland the empty string valid; the policy the one of the sanitizer the validator is built with.- The documentation in
doc/, one file per topic, indexed by the README. CONTRIBUTING.md,SECURITY.mdandCODE_OF_CONDUCT.md.