Download the PHP package rhukster/dom-sanitizer without Composer
On this page you can find all versions of the php package rhukster/dom-sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rhukster/dom-sanitizer
More information about rhukster/dom-sanitizer
Files in rhukster/dom-sanitizer
Package dom-sanitizer
Short Description A simple but effective DOM/SVG/MathML Sanitizer for PHP 7.4+
License MIT
Informations about the package dom-sanitizer
DOMSanitizer
A simple but effective DOM/SVG/MathML Sanitizer for PHP 7.3+. This was created due to my requirements for a performant DOM and specifically SVG sanitizer that was MIT compatible.
This borrows the extensive list of valid tags and attributes in the excellent DOMPurify library for JavaScript, but uses PHP DOMDocument to parse the DOM and filter out dangerous tags and attributes.
Installation
Options
Options can be passed to the sanitize() method as an optional array. Default values are:
Usage
Sanitizing HTML
The default option but provides with the full list of HTML tags and attributes.
Sanitizing SVG
You can limit the valid tags and attributes by passing DOMSanitizer::SVG to the constructor. This is advisable if you know you are dealing with SVGs.
Processing instructions and comments are removed, and CDATA content is preserved as escaped text, so these XML constructs cannot hide HTML markup when sanitized SVG is embedded inline. These checks also apply to MathML and do not depend on the output options.
Animations targeting URL attributes (including href and xlink:href), event handlers, style, or XML namespace declarations are removed entirely, even if their values appear harmless. Normal transform, color, and motion animations remain supported.
Sanitizing MathML
You can limit the valid tags and attributes by passing DOMSanitizer::MATHML to the constructor. This is advisable if you know you are dealing with MathML code.
Modifying the allowed tags and attributes
You have full access to the tags and attributes via the following methods:
All versions of dom-sanitizer with dependencies
ext-dom Version *
ext-libxml Version *