Css-sanitizer

The CSS Sanitizer library implements a CSS tokenizer, parser and grammar matcher in PHP that mostly follows the CSS Syntax Module Level 3 candidate recommendation dated 20 February 2014, the CSS Values and Units Module Level 3, and the CSS Selectors Level 3 grammar. It also provides a sanitizer that recognizes various CSS3 modules.

This library was developed for use in the TemplateStyles extension for MediaWiki.

History
We required a CSS sanitizer with several properties:


 * Strict parsing according to modern standards.
 * Includes line and character position for all errors.
 * Configurable to limit unsafe constructs such as external URL references.
 * Errors are easily localizable.

We could not find a library that fit these requirements, so we created one.