Repository navigation
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
🟡 Changes recommended
Null preset entries and null slugs can bypass the new validation.
1 open finding
What changed in this PR
Sanitizes malformed theme.json preset entries to prevent stylesheet-generation failures.
Changes:
- Filters non-array presets and non-scalar slugs.
- Covers root, block, and origin-keyed presets.
- Adds regression tests for sanitization and KSES paths.
| File | Description |
|---|---|
src/wp-includes/class-wp-theme-json.php |
Filters malformed preset entries during sanitization. |
tests/phpunit/tests/theme/wpThemeJson.php |
Adds malformed-preset regression coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Preset leaves are untyped in `VALID_SETTINGS`, so a preset item that isn't an array, or whose `slug` isn't a scalar, reached code that reads `$preset['slug']` as a string and threw a fatal `TypeError`. `WP_Theme_JSON::sanitize()` now removes those items from plain preset lists and from lists keyed by origin, at the top level and per block. Filtering in `sanitize()` also covers `remove_insecure_properties()`, which the kses filter uses when global styles are saved. Scalar slugs are kept, so an integer `slug` still works. Backports WordPress/gutenberg#84534. See #66304.
cfb3563 to
556b753
Compare
tellthemachines
left a comment
There was a problem hiding this comment.
Changes are consistent with WordPress/gutenberg#84534; LGTM!
… fatals in PHP This commit prevents `WP_Theme_JSON` from throwing fatal TypeErrors when preset items in theme.json or global styles data contain values of the wrong type. Those values could be user- or AI-generated. It does this by removing theme.json preset items that aren't objects, or whose `slug` isn't a scalar, in `WP_Theme_JSON::sanitize()`. Previouly, for example, a preset list of strings, such as `"fontFamilies": [ "Inter" ]`, failed with `Cannot access offset of type string on string` when the stylesheet is generated. Developed in: #14262 Props ramonopoly, aaronrobertshaw, isabel_brison. Fixes #66304. git-svn-id: https://develop.svn.wordpress.org/trunk@64491 602fd350-edb4-49c9-b593-d223f7449a82
… fatals in PHP This commit prevents `WP_Theme_JSON` from throwing fatal TypeErrors when preset items in theme.json or global styles data contain values of the wrong type. Those values could be user- or AI-generated. It does this by removing theme.json preset items that aren't objects, or whose `slug` isn't a scalar, in `WP_Theme_JSON::sanitize()`. Previouly, for example, a preset list of strings, such as `"fontFamilies": [ "Inter" ]`, failed with `Cannot access offset of type string on string` when the stylesheet is generated. Developed in: WordPress/wordpress-develop#14262 Props ramonopoly, aaronrobertshaw, isabel_brison. Fixes #66304. Built from https://develop.svn.wordpress.org/trunk@64491 git-svn-id: http://core.svn.wordpress.org/trunk@63641 1a063a9b-81f0-0310-95a4-ce76da25c4cd

Trac ticket: https://core.trac.wordpress.org/ticket/66304
Backports WordPress/gutenberg#84534
Follow-up to https://core.trac.wordpress.org/changeset/64309
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.