Opened 7 days ago
Closed 44 hours ago
#66304 closed enhancement (fixed)
Global Styles: Remove preset items of unexpected types to prevent fatals in PHP
| Reported by: | ramonopoly | Owned by: | ramonopoly |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | General | Version: | 5.8 |
| Severity: | normal | Keywords: | has-patch has-unit-tests gutenberg-merge |
| Cc: | Focuses: |
Description (last modified by )
Follow up to https://core.trac.wordpress.org/ticket/66286
Tracks backport of https://github.com/WordPress/gutenberg/pull/84534
To prevent fatals caused by invalid theme.json values:
- remove preset items that aren't objects, or whose slug isn't a scalar, in
WP_Theme_JSON::sanitize().
Invalid theme.json values can be introduced via the global styles CPT, e.g., if an AI-generates it for you!
Change History (5)
This ticket was mentioned in PR #14262 on WordPress/wordpress-develop by @ramonopoly.
7 days ago
#1
#2
@
7 days ago
- Description modified (diff)
- Summary Global Styles: Remove preset items of unexpected types → Global Styles: Remove preset items of unexpected types to prevent fatals in PHP
#3
@
4 days ago
I’m going through the 7.2 tickets ahead of beta 1.
Thank you for the work on this, @ramonopoly. I see the Gutenberg PR is merged, while the core PR still needs a review, and beta 1 is only a few days away.
Is 7.2 a realistic target for this? If it needs more time, we can move it to 7.3.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Backports https://github.com/WordPress/gutenberg/pull/84534
Follow-up to https://core.trac.wordpress.org/changeset/64309 (#66286).
What
Removes theme.json preset items that aren't objects, or whose
slugisn't a scalar, inWP_Theme_JSON::sanitize().Why
Preset leaves are untyped in
VALID_SETTINGS, so these items reach code that reads$preset['slug']as a string. On trunk they throw a fatalTypeError:"fontFamilies": [ "Inter" ], fails withCannot access offset of type string on stringwhen the stylesheet is generated.slugfails inpreg_match_all().remove_insecure_settings().What changed
sanitize()drops those items from plain preset lists and from lists keyed by origin, at the top level and per block. The filter lives insanitize()rather than the constructor becauseremove_insecure_properties()(the kses save path) callssanitize()but never constructs aWP_Theme_JSON.slugstill works.Valid data is unaffected. The Gutenberg PR also changes
get_base_custom_css(), which only exists in the plugin, so there's nothing to port for it.Each case has a test. All seven new cases fail on trunk.