-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Core backport for Global Styles: Allow arbitrary CSS, protect from KSES mangling #74371
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
Core backport for Global Styles: Allow arbitrary CSS, protect from KSES mangling #74371
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
These are issues related to the error message. It may not be displayed or the actual message is ignored: |
|
Thanks for preparing this. I would like to wait until WordPress/wordpress-develop#10641 lands before merging this so that the final implementations match. |
Good plan! |
|
Flaky tests detected in 3b2ca0d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20979791382
|
…idation logic. Added escaping for JSON data to prevent HTML filter issues and refined CSS validation to ensure it does not break HTML style tags.
a61dc94 to
3b2ca0d
Compare
sirreal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a correct sync of the global styles REST controller in https://core.trac.wordpress.org/changeset/61486.
…c-64418-from-core
|
This broke an multisite unit test against the previous major WordPress version: The test result depends on the KSES global styles filter being fixed like was done in [61486]. The failure demonstrates that this problem cannot be fixed in Gutenberg alone. I'm tempted to revert this change until Gutenberg drops support for WordPress 6.9. I'm exploring options in #74731 |
…ES mangling (#74371) Backport https://core.trac.wordpress.org/changeset/61486 to address https://core.trac.wordpress.org/ticket/64418. - Add JSON encoding flags to `WP_REST_Global_Styles_Controller_Gutenberg` (`JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP`) to prevent HTML filtering issues. - Update `validate_custom_css()` to allow arbitrary CSS and reject possible `</style>` closing tags. --------- Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: dmsnell <dmsnell@git.wordpress.org>
…ES mangling (#74371) Backport https://core.trac.wordpress.org/changeset/61486 to address https://core.trac.wordpress.org/ticket/64418. - Add JSON encoding flags to `WP_REST_Global_Styles_Controller_Gutenberg` (`JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP`) to prevent HTML filtering issues. - Update `validate_custom_css()` to allow arbitrary CSS and reject possible `</style>` closing tags. --------- Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: dmsnell <dmsnell@git.wordpress.org>
…SES mangling (#74731) Complete the backport of https://core.trac.wordpress.org/changeset/61486. #74371 was a partial backport but omitted some necessary filter changes. --- Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: dmsnell <dmsnell@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
A PR to backport WordPress/wordpress-develop#10641, which fixes https://core.trac.wordpress.org/ticket/64418
WP_REST_Global_Styles_Controller_Gutenberg(JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP) to prevent HTML filter issuesvalidate_custom_css(): replace regex with targeted validation that only blocks</style>tagsAll props go to @sirreal and @dmsnell and other folks working on that PR.
Why?
So that folks running the latest Gutenberg on top of any version of WordPress (even after WordPress/wordpress-develop#10641 lands in 7.0) can benefit from the fix.
Gutenberg overwrites the controller for the
wp_global_stylespost type viaWP_REST_Global_Styles_Controller_Gutenberg.Quoting WordPress/wordpress-develop#10641:
Under some circumstances KSES would run post content filters and change the resulting content like this:
@property --animate { - syntax: "<custom-ident>"; + syntax: ""; inherits: true; initial-value: false; }The Custom CSS is stored as JSON-encoded data in post content. KSES filters this content as HTML.
Testing
Head over the to site editor, open Global styles, then "Additional CSS" from the ellipsis dropdown.
Add some CSS rules that contain CSS properties, e.g.,
You should be able to save this content (on trunk you can't)
Now try to add a closing
</style>tag to the content.You should be blocked by the server with a
rest_custom_css_illegal_markup400 error.Screenshots or screencast