-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Malformed CSS properties leak AMP validation error past the sanitizer #4113
Comments
I think a CSS validator would be needed here to ensure any form of malformed CSS is not leaked. Unfortunately there isn't any PHP CSS validator library (that I could find) that would fit the requirements here, and the one being used by W3C is in Java. The easiest fix I think may be to get a list of valid CSS rule sets to validate against for now. |
The PHP-CSS-Parser should be handling this during parsing. It has a loose parsing mode that recovers from parsing errors, and I think this should fall into that category and be stripped. The issue is just that the property doesn't match the required pattern. |
Here's the PHP-CSS-Parser code in question: https://github.com/sabberworm/PHP-CSS-Parser/blob/a80a97d3fdb2164d72cbf0fb3cfc40b1d630a877/lib/Sabberworm/CSS/Rule/Rule.php#L34-L38 I think the problem is that In particular, the Note the ranges allowed:
So this means that
So PHP-CSS-Parser is not taking into account the restriction in |
Ah I see. I'll review this to ensure it fixes the reported bug here and make a PR to sabberworm/PHP-CSS-Parser with the fix. |
I've opened MyIntervals/PHP-CSS-Parser/pull/185 to address this. |
Verified in QA |
Bug Description
When a theme or plugin adds CSS like the following:
Notice the
-0-transition
. This causes an AMP validation error:The same thing happens in a theme like
organic-lite
(on WordPress.org) which has instances of an invalid property4z-index:1;
.Expected Behaviour
Such invalid CSS properties should be removed by the style sanitizer.
Steps to reproduce
<style>...</style>
tag.Screenshots
Additional context
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
It is not clear to me whether this should be fixed in the AMP plugin or rather in PHP-CSS-Parser. I think it actually should be addressed in the latter because such CSS is actually a syntax error:
So I think the PHP-CSS-Parser should be updated to strip such invalid properties from the parsed rules.
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: