-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Intent to Implement: CSS @media query validation #18246
Comments
Which media query types/features will no longer be valid? |
Anything not in the whitelist. However, any type/feature we find used with any significance on the AMP corpus will be added to the AMP whitelist. Some of the ones in that list fall in that category, such as "-sass-debug-info". |
few older types to add: |
@aghassemi I updated the first post to add those 7 to the list. |
LGTM |
LGTM |
Is this I2I still active? |
Yes. However, I think it's still in need of a third LGTM to make progress? |
We could probably consider this one grandparented in, but it doesn't hurt. :) cc @ampproject/wg-approvers for a third pre-approval LGTM |
3rd LGTM |
This has been implemented as a warning only. I don't anticipate we'll want to move to an error for AMP, only email, so closing this. |
Current behavior
The AMP Validator currently emits validation parse errors on malformed CSS in custom stylesheets (
<style amp-custom>
and<style amp-keyframes>
). For example, publishers may see an error with attached line/column information such as:The validator does not currently parse @media query strings, for example, the string
screen and (max-width: 500px)
within the CSS block@media screen and (max-width: 500px) {}
.It also does not make any assertions on the valid values for media query types (ex.
screen
) or media query features (ex.max-width
).Intended change
This proposed change is to invalidate documents containing parse errors in @media query strings, and validate media types and features against a whitelist of allowed values, depending on the context. See the below sections for additional detail.
Parse Errors
If there are errors generated while parsing CSS media queries, browsers will currently discard the entire encountered @media rule. The AMP Validator ignores these cases, but will begin to detect and report on them. The generated validator messages will look like:
And will attach line / column information referencing the start of the media query.
Examples of invalid media queries include:
screen and(max-width:500px)
screen and
screen,
screen (
((min-width:500px))
&test, screen
not only screen and (color)
A sample of 10,000 crawler-accessible pages shows 11 amp documents (0.11%) that would become invalid if media query parsing would report a validator error.
Whitelist of valid media query types and features
The set of media query types (ex.
screen
) and media query features (ex.max-width
) will be whitelisted by the validator.For normal AMP documents, it is intended that all types and features with any significant use will be whitelisted, so only uncommon typos will become invalid. The current list, which will be extended after wider testing includes:
This list assumes that
min-
,max-
prefix variations, as well as vendor prefix variations (-o-
,-moz
,-ms-
,-webkit-
) of the above will also be considered valid.The validation messages will look like:
For AMP documents, we will whitelist any commonly observed type or feature, so the impact should be very small and limited to rare typos.
For other types of AMP documents, such as AMP4ADS or AMP4EMAIL, the whitelist will be constrained to a smaller subset.
AMP4ADS:
AMP4EMAIL: TBD
Purpose of Change
Some media query types and features can be used to fingerprint user browsers representing a security and privacy risk in some contexts. Adding this functionality to manage access to media query parameters allows AMP providers to manage this risk.
Suggested Change Schedule
Upon approval of this change, the AMP validator will begin emitting warnings for documents that contain unparseable media queries or use media query types or features not on the proposed whitelist. These warnings will not cause AMP documents to become invalid, but will give developers time to understand the impact of the change. Warnings will appear in all AMP validator interfaces, including Google Search Console.
No sooner than 6 weeks after warnings have been emitted, these warnings will become errors, and documents with these warnings will become invalid.
For process reference, see spec/amp-versioning-policy.md.
The text was updated successfully, but these errors were encountered: