Changelog
phil/css-sanitizerAll notable changes to phil/css-sanitizer will be documented in this file.
Updates should follow the Keep a CHANGELOG principles.
NEXT - YYYY-MM-DD
Added
CssSanitizer:sanitize()for style sheets andsanitizeDeclarations()forstyleattributes, returningSanitized— the CSS, the kept rules asSheet\StyleSheet,Sheet\ImportRule,Sheet\StyleRuleandSheet\GroupRule, the kept declarations — and eachRemovalwith itsRemovalReason, subject and line, the firstSanitized::MAX_REMOVALS(100) listed and the others counted inomittedRemovals.Policy: allow lists of properties, functions, pseudo-classes, pseudo-elements, attributes, media types and at-rules with defaults for screen and print, a scope selector,!importantand custom properties, limits of length, depth and nesting levels; the properties and functions that run code or load a resource can never be allowed (InvalidPolicy).UrlRewriterandUrlKind, withUrl\RefuseUrls,Url\AllowedFilesandUrl\CallbackRewriter: every URL — images, fonts, the style sheets of@import— rewritten or refused, fragments kept without asking,javascript:,vbscript:,livescript:andmocha:refused before and after the rewriter.- Selectors checked against the grammar of Selectors Level 4 — type, universal, class, ID and attribute selectors,
pseudo-classes with their arguments, pseudo-elements, combinators — and the policy's names; nested selectors
relative to their parent, with
&refused inside:not(),:is()and:where()so that it cannot leave the scope. - Values checked token by token: allowed functions with their arguments,
url()and each image ofimage-set()through the rewriter,type()beside them,attr()with the typeurlonly insidetarget-counter(),target-counters()andtarget-text(). - At-rules:
@mediawith the policy's media types and features that load nothing,@supportswithout URLs,@pagewith its page selectors, its descriptors and its sixteen margin boxes,@font-facewith its descriptors and its local or rewritten sources;@importat the start of a sheet, when the policy allows it, rewritten to an allowed style sheet with itssupports()and media conditions; every other at-rule refused. - CSS Nesting: style rules,
@mediaand@supportsnested in a style rule, read as a block's contents, their levels bounded by the policy (RemovalReason::Nesting), declarations written before nested rules. Syntax\Tokenizer, the tokenizer of CSS Syntax Level 3 written from the specification: the input preprocessed and made valid UTF-8, every token with its escapes resolved, comments dropped, bad strings and bad URLs, the line of each token.Syntax\Parser, the parser of CSS Syntax Level 3: component values, simple blocks and functions, lists of rules and of declarations, a block's contents as CSS Nesting reads them,!important, what the specification drops kept asMalformed, nesting bounded byNestingTooDeep;Token,SimpleBlock,FunctionValue,QualifiedRule,AtRule,DeclarationandStylesheet.Serializer: component values, declarations and sanitized style sheets written back as CSS, identifiers and strings escaped as CSSOM does, URLs asurl("…"), an empty comment where two tokens would join,<escaped or kept apart from/so that the output never starts an end tag.CssSanitizerException, implemented byInvalidPolicyandNestingTooDeep.Validator\SafeCssandValidator\SafeCssValidator, a constraint forsymfony/validator: each removal a violation, and the removals past the first 100 one more,moreMessage, with their count.- The documentation in
doc/, one file per topic, indexed by the README. CONTRIBUTING.md,SECURITY.mdandCODE_OF_CONDUCT.md.