Repository navigation
🐛 fix(sanitize): split CSS tokens where browsers split them - #2137
Merged
Merged
Conversation
The CSS scrubber stepped over `<!--`, `#name` and `@name` one code point at a time, so it disagreed with a browser about whether a following `url(` starts a url token. It could then take the inside of a browser declaration for a string and keep it, letting properties outside css_properties reach style attributes and <style> bodies. These tokens only matter when the name after them is followed by `(` or `+`, so the check runs there, out of line, and looks back at what precedes the name: a `#` or `@` makes it a hash or at-keyword name, and an unescaped `<!` before `--` makes the name start after the CDO. Other names pay one compare. The scheme check steps over url token bodies so a comment opener inside one hides nothing after it, and a declaration or rule holding a legacy unicode-range token is dropped, since tokenizers disagree on where that token ends.
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scrubber behind
styleattributes and<style>bodies split CSS into declarations at different places than a browser does for some inputs. Text the scrubber held to be inside one declaration's string orurl()could be a separate declaration to a browser. A sanitizer that allowsstylecould therefore let through properties outside itscss_propertiesallow-list. 🔒 After this change the scrubber splits where a browser splits, and drops the few constructs that browsers tokenize differently.Architecture
The token skipper now treats the CDO token, hash and at-keyword tokens the way CSS Syntax Level 3 does, so
url(after them starts a url token only where a browser starts one. The fast path is unchanged: only a name followed by(or+takes the out-of-line check, which looks back at what precedes the name. The scheme check applies the same CDO rule, so aurl()orexpression()right after a CDO is checked.A comment opener inside a url token no longer hides the tokens after it, because a url token's body holds no strings or comments and the scanner now steps over it.
Behavior changes
unicode-rangedescriptor. CSS Syntax Level 3 removed the unicode-range token, and tokenizers that keep it disagree on where it ends, so the scrubber drops a<style>rule whose prelude holds one as well.url()whose body holds a comment opener is now checked by the scheme check.Fixes #1768.