Skip to content

KSES: Allow CSS colour functions in inline styles - #84213

Merged
aaronrobertshaw merged 7 commits into
trunkfrom
fix/kses-css-color-functions
Oct 30, 2026
Merged

aaronrobertshaw merged 7 commits into
trunkfrom
fix/kses-css-color-functions

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What?

safecss_filter_attr() drops any declaration whose value uses a CSS colour function. This keeps them: rgb(), rgba(), hsl(), hsla(), hwb(), lab(), lch(), oklab(), oklch(), color(), color-mix() and light-dark().

Why?

These are all dropped today:

  • box-shadow: 1px 1px 1px rgba(0,0,0,0.5)
  • box-shadow: 6px 6px 9px rgb(0 0 0 / 20%), 0 0 0 1px hsl(0 0% 0%)
  • color: oklch(70% 0.1 200)
  • color: color-mix(in srgb, #fff 50%, #000)

The style engine runs its output through the same function, so a shadow, border colour or text colour written this way never reaches the page. Gradients already have an exception (#79791).

How?

A new safecss_filter_attr_allow_css filter in lib/compat/wordpress-7.3/kses.php.

It only takes effect when a colour function is present and only approves one whose contents are plain colour syntax, innermost first so nested values work. It runs before other filters, so a rejection from another filter stands. Everything else is checked as before.

Core backport: Trac ticket 66387 adds the same check to safecss_filter_attr() for WordPress 7.3.

Testing Instructions

  1. Log in as an Author, so post content goes through KSES. In the code editor, add:
    <!-- wp:paragraph {"style":{"shadow":"6px 6px 9px rgba(0,0,0,0.5)","color":{"text":"color-mix(in srgb, #c00 70%, #000)"}}} -->
    <p class="has-text-color" style="color:color-mix(in srgb, #c00 70%, #000);box-shadow:6px 6px 9px rgba(0,0,0,0.5)">Color functions</p>
    <!-- /wp:paragraph -->
  2. Save and reload. The shadow and text colour still apply, in the editor and on the front end. On trunk both are stripped on save.

Use of AI Tools

Implemented and tested by a Claude Code agent from a predefined task.

@aaronrobertshaw aaronrobertshaw added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement. [Package] Block library /packages/block-library Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Oct 8, 2026
@aaronrobertshaw aaronrobertshaw self-assigned this Oct 8, 2026
@github-actions github-actions Bot removed the [Package] Block library /packages/block-library label Oct 8, 2026
@aaronrobertshaw
aaronrobertshaw force-pushed the fix/kses-css-color-functions branch 2 times, most recently from 8b91a66 to f9141c2 Compare October 8, 2026 05:56
@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric cc488f9 trunk % Change
timeToFirstByte 36.85 ms +14.93% -5.97% 35.4 ms +5.51% -7.2% 4.1%
largestContentfulPaint 64 ms +6.25% -6.25% 60 ms +10% -6.67% 6.67%
lcpMinusTtfb 25.55 ms +15.66% -8.22% 24.2 ms +10.54% -3.1% 5.58%
wpBeforeTemplate 19.18 ms +24.71% -3.44% 18.32 ms +14.36% -3.82% 4.69%
wpTemplate 14.22 ms +2.46% -7.1% 13.78 ms +2.1% -9.43% 3.19%
wpTotal 33.73 ms +13.64% -6.11% 32.31 ms +6.25% -7.4% 4.39%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.44%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric cc488f9 trunk % Change
timeToFirstByte 30.4 ms +6.41% -2.96% 26.35 ms +7.4% -3.04% 15.37%
largestContentfulPaint 68 ms +5.88% -0% 60 ms +0% -3.33% 13.33%
lcpMinusTtfb 38.45 ms +3.9% -1.3% 33.15 ms +1.51% -7.24% 15.99%
wpBeforeTemplate 16.62 ms +7.34% -0.9% 16.06 ms +4.67% -1.43% 3.49%
wpTemplate 10.58 ms +5.39% -2.17% 7.82 ms +1.41% -7.54% 35.29%
wpTotal 27.79 ms +6.05% -2.91% 23.94 ms +7.98% -3.01% 16.08%
wpMemoryUsage 6.40 MB +0% -0% 6.25 MB +0% -0% 2.34%
wpDbQueries 13 +0% -0% 9 +0% -0% 44.44%

media-processing

Metric cc488f9 trunk % Change
mediaProcessingJpeg 232.23 ms +1.81% -1.14% 225.44 ms +2.24% -0.39% 3.01%
mediaProcessingAvif 3738.51 ms +1.53% -0.6% 3823.12 ms +0.35% -1.48% -2.21%
mediaProcessingJpegToAvif 2600.88 ms +1.01% -0.37% 2725.52 ms +2.36% -0.81% -4.57%

media-upload

Metric cc488f9 trunk % Change
jpegUploadProcessing 1418.89 ms +1.33% -1.36% 1412.49 ms +0.3% -0.45% 0.45%
pngUploadProcessing 184.05 ms +5.38% -2.88% 186.47 ms +16.22% -3.48% -1.3%
largeJpegUploadProcessing 1405.58 ms +0.77% -1.25% 1403.57 ms +1.02% -0.86% 0.14%
multipleImageUploadProcessing 1448.39 ms +0.46% -0.28% 1446.3 ms +1.02% -0.4% 0.14%

post-editor

Metric cc488f9 trunk % Change
serverResponse 545.15 ms +5.6% -5.61% 567.83 ms +3.84% -1.44% -3.99%
firstPaint 293.06 ms +60.4% -12.73% 458.48 ms +17.69% -32.11% -36.08%
domContentLoaded 924.88 ms +2.94% -3.81% 929.9 ms +1.31% -1.45% -0.54%
loaded 926.1 ms +2.93% -3.77% 931.15 ms +1.33% -1.45% -0.54%
firstContentfulPaint 540.97 ms +3.23% -8.16% 539.24 ms +1.06% -0.61% 0.32%
firstBlock 3082.31 ms +1.59% -0.83% 3104.17 ms +1.07% -1.34% -0.7%
type 19.12 ms +3.61% -5.28% 20.24 ms +12.35% -1.78% -5.53%
typeWithoutInspector 20.03 ms +6.34% -4.44% 19.44 ms +11.99% -7.41% 3.03%
typeWithTopToolbar 25.29 ms +6.41% -2.89% 25.29 ms +4.47% -8.78% 0%
typeContainer 9.24 ms +7.68% -9.2% 8.97 ms +3.68% -5.8% 3.01%
focus 125.76 ms +9.81% -3.64% 121.97 ms +8.68% -4.72% 3.11%
firstFocus 238.83 ms +0% -0% 242.92 ms +0% -0% -1.68%
selectAll 486.39 ms +4.25% -0.7% 499.41 ms +1.48% -7.38% -2.61%
undo 33.42 ms +4.43% -6.1% 33.15 ms +6.76% -3.2% 0.81%
listViewOpen 83.05 ms +8.99% -4.49% 85.07 ms +5.16% -14.19% -2.37%
inserterOpen 43.85 ms +9.99% -10.65% 43.29 ms +11% -5.84% 1.29%
inserterHover 12.2 ms +4.43% -9.67% 12.61 ms +8.01% -9.04% -3.25%
inserterSearch 8.83 ms +4.53% -4.98% 8.38 ms +10.62% -8.71% 5.37%
loadPatterns 685.21 ms +3.72% -3.04% 679.08 ms +3.17% -4.81% 0.9%
wpTotal 534.42 ms +5.63% -5.61% 556.45 ms +3.86% -1.27% -3.96%
wpMemoryUsage 14.73 MB +0% -0% 14.72 MB +0% -0% 0.1%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric cc488f9 trunk % Change
serverResponse 544.34 ms +1.24% -6.83% 544.89 ms +7.91% -7.21% -0.1%
firstPaint 300.5 ms +7.94% -10.07% 281.65 ms +14.13% -11.98% 6.69%
domContentLoaded 941.56 ms +1.28% -0.57% 940.57 ms +1.01% -1.36% 0.11%
loaded 942.95 ms +1.27% -0.61% 941.91 ms +0.98% -1.36% 0.11%
firstContentfulPaint 533.33 ms +3.16% -2.33% 525.1 ms +1.9% -4.64% 1.57%
firstBlock 4141.57 ms +0.5% -0.9% 4098.42 ms +1.07% -0.98% 1.05%
type 20.12 ms +6.36% -13.57% 20.52 ms +11.79% -5.6% -1.95%
navigate 121.88 ms +4.14% -1.03% 126.49 ms +9.56% -1.87% -3.64%
loadPatterns 1278.07 ms +5.88% -11.98% 1252.06 ms +2.24% -3.46% 2.08%
loadPages 1039.49 ms +1.68% -1.57% 1088.26 ms +0.73% -6.25% -4.48%
wpTotal 534.39 ms +1.34% -7.01% 534.71 ms +8.13% -7.23% -0.06%
wpMemoryUsage 12.77 MB +0% -0% 12.73 MB +0% -0% 0.28%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

f2f61e7 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Delete (forward) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  5
+ Received  + 11

@@ -1,25 +1,31 @@
  Array [
    Object {
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "1‸a",
          },
-         "innerBlocks": Array [
+         "innerBlocks": Array [],
+         "name": "core/list-item",
+       },
        Object {
+         "attributes": Object {
+           "content": "2",
+         },
          "innerBlocks": Array [
            Object {
              "attributes": Object {
-                   "content": "a‸2",
+               "ordered": false,
+               "values": "",
              },
-                 "name": "core/list-item",
-               },
+             "innerBlocks": Array [
                Object {
                  "attributes": Object {
                    "content": "b",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
            },

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:2056:42
Navigates the items list via UP/DOWN arrow keys (Site Editor v2) in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page One')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page One') with timeout 5000ms
  - waiting for getByLabel('Page One')
    14 × locator resolved to <button type="button" aria-pressed="true" data-active-item="true" id="view-list-0-12-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-12-label" aria-describedby="view-list-0-12-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:149:49
image inserted via upload should appear in the frontend published post content in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:8889/wp-json/wp/v2/media?per_page=100
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: e940189869
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1793427330%7C8uWfop7J98lAebbyAc1v1XuYFVd91Su1hajrUvzDssY%7C9752af377ae14d1d3d98fa0339f8489c1ee9b138317e236f6d337e8c36916ad8; wp-settings-time-1=1793254561

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:111:39)
    at RequestUtils.listMedia (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/media.ts:24:30)
    at RequestUtils.deleteAllMedia (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/media.ts:85:27)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:16:22
inserts a block should show a blue line indicator in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TypeError: Cannot read properties of null (reading 'y')
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:681:32
should change the indented list type in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Indent"]')
    - locator resolved to <button id="_r_1l_" type="button" tabindex="-1" aria-label="Indent" aria-disabled="true" data-toolbar-item="true" data-truly-disabled="false" aria-describedby="components-button__description-26" class="components-button components-toolbar-button is-compact has-icon">…</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
    - waiting 20ms
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
      - waiting 100ms
    18 × waiting for element to be visible, enabled and stable
       - element is not enabled
     - retrying click action
       - waiting 500ms

    at Editor.clickBlockToolbarButton (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/click-block-toolbar-button.ts:17:15)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:727:3
should cut and paste individual blocks with collapsed selection in /test/e2e/specs/editor/various/copy-cut-paste.spec.js, passed after 1 failed attempt.
Error: expect(string).toMatchSnapshot(expected) failed

  @@ -1,3 +1,3 @@
   <!-- wp:paragraph -->
  -<p>2Cut - collapsed selection</p>
  +<p>2</p>
   <!-- /wp:paragraph -->


    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/copy-cut-paste.spec.js:45:49
should format text across blocks in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "ab",
+       "content": "b",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:2219:41
should indent and outdent a list item when its content is fully selected in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 7
+ Received  + 7

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a<!-- wp:list -->
- <ul class="wp-block-list"><!-- wp:list-item -->
- <li>b</li>
+ <li></li>
+ <!-- /wp:list-item --></ul>
- <!-- /wp:list-item --></ul>
+ <!-- /wp:list -->
+
- <!-- /wp:list --></li>
- <!-- /wp:list-item --></ul>
+ <!-- wp:paragraph -->
+ <p>b</p>
- <!-- /wp:list -->
+ <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:819:52
should indent and outdent level 1 in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Indent"]')

    at Editor.clickBlockToolbarButton (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/click-block-toolbar-button.ts:17:15)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:775:3
should insert a line break on shift+enter in a non trailing list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 10
+ Received  + 10

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a</li>
+ <li></li>
- <!-- /wp:list-item -->
-
+ <!-- /wp:list-item --></ul>
- <!-- wp:list-item -->
+ <!-- /wp:list -->
+
+ <!-- wp:paragraph -->
- <li>b<br></li>
+ <p>b<br></p>
- <!-- /wp:list-item -->
+ <!-- /wp:paragraph -->

- <!-- wp:list-item -->
+ <!-- wp:paragraph -->
- <li>c</li>
+ <p>c</p>
- <!-- /wp:list-item --></ul>
- <!-- /wp:list -->
+ <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1233:52
should merge a following sibling list into the outermost list with Delete from a nested item (#77245) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

@@ -8,11 +8,11 @@
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
-                   "content": "b‸",
+                   "content": "b",
                  },
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
@@ -25,11 +25,11 @@
    },
    Object {
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "‸1",
          },
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:2854:41
should not undo asterisk transform with backspace after selection change in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeVisible() failed

Locator: locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/list"]')
Expected: visible
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeVisible" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/list"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/list"]')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:243:5
should partially select with shift + click in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  1
+ Received  + 11

  Array [
    Object {
      "attributes": Object {
-       "content": "<strong>1</strong>|2",
+       "content": "<strong>1</strong>[",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
+     "name": "core/paragraph",
+   },
+   Object {
+     "attributes": Object {
+       "content": "]2",
+       "dropCap": false,
      },
+     "innerBlocks": Array [],
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:1599:41
should push only the selected subset of styles in /test/e2e/specs/site-editor/push-to-global-styles.spec.js, passed after 1 failed attempt.

Truncated. See the full report.

f2f61e7 Run

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this up! I know there's a long ramp to 7.3, so I appreciate the early PR.

I'm for this change, but it'd good to understand what these CSS open up.

I'm imagining it'd be handy for theme devs, or anyone (or anything) generating global styles by hand. Are there any implications for block tools in the editor?

Soft ping to @sirreal just for awareness as it relates to some of what folks have been thinking about in relation to the kses vs valid CSS cage fight

Comment thread lib/compat/wordpress-7.3/kses.php Resolved
}
}

$css_test_string = preg_replace( $color_function, '0', $css_test_string );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that Core has always checked CSS this way, i.e., by removing each passing bit and replace it with 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. My understanding is so that a nested function still leaves a value for the outer check.

Comment thread lib/compat/wordpress-7.3/kses.php Resolved
The shim ran at priority 10 and turned Core's false into true, so it
also overrode a filter that rejected the same declaration at an earlier
priority. Running it at PHP_INT_MIN makes it act like Core's own check:
later filters still get the final say.

Tests now reject `color: rgb(0 0 0)` from filters at priorities 5 and
10, and cover characters left over after a colour function.
Lower the nesting cap from 32 to 4, the deepest real combination of colour functions, and explain it in a comment. Run the final leftover check after the loop so the shim keeps exactly the cap. Reword the docblock to say the shim runs first.

The rejection test now uses __return_false, because Core passes the filter the test string with colour functions already replaced. Test 4 levels kept and 5 dropped, and skip the drop test when Core already allows colour functions.
@aaronrobertshaw
aaronrobertshaw force-pushed the fix/kses-css-color-functions branch from b70d26e to c843479 Compare October 28, 2026 12:26
@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

Appreciate the in depth review and questions @ramonjd 👍

I'm for this change, but it'd good to understand what these CSS open up.

It doesn't open up anything beyond colour values. Only the listed colour functions are recognised, their contents have to be plain colour syntax (numbers, units, hex, keywords, / and ,), nesting is capped at 4 now, and anything left over still goes through the existing check.

Are there any implications for block tools in the editor?

Not really. The colour pickers still save hex.

Where it does show up though is:

  • Global Styles shadows. A new custom shadow starts as 6px 6px 9px rgba(0, 0, 0, 0.2), and editing its offsets or blur keeps that colour. For users without unfiltered_html, saving currently drops the whole preset.
  • Anything output through the style engine, which runs every declaration through safecss_filter_attr() for all users. An rgba() shadow or colour set in block markup, a pattern or PHP gets dropped on render. That's how this came up in Shadow: Add a PHP helper for block support classes and styles #84205.

Shadows picked in the block inspector aren't affected, since they're saved as preset references and output as var().

aaronrobertshaw added a commit to aaronrobertshaw/wordpress-develop that referenced this pull request Oct 28, 2026
`safecss_filter_attr()` rejected any declaration containing a color function such as `rgb()`, `hsl()` or `color-mix()`, so styles like a `box-shadow` with an `rgba()` color were stripped.

Color functions are now removed from the test string, innermost first, when their contents are plain color syntax. Anything left over, such as a parenthesis, backslash, comment or unknown function, is still rejected, and the `safecss_filter_attr_allow_css` filter can still reject the declaration.

Synced from WordPress/gutenberg#84213.

Fixes #66387.
@sirreal

sirreal commented Oct 28, 2026

Copy link
Copy Markdown
Member

A change like this is overdue.

I've been working on CSS foundations in WordPress/wordpress-develop#14781. Building on that foundation, I re-implemented safecss_filter_attr() in WordPress/wordpress-develop#14784 (similar in spirit to the KSES Tag Processor re-implementation in r64233). One choice there was to allow all of these functions that don't seem to be problematic and simply haven't been allowed yet.

None of the work is ready for any serious review at this time, but it could make this change obsolete. No promises and that doesn't block this work. I'd be very happy to land things early in the 7.3 cycle.

@ramonjd

ramonjd commented Oct 28, 2026

Copy link
Copy Markdown
Member

A new custom shadow starts as 6px 6px 9px rgba(0, 0, 0, 0.2), and editing its offsets or blur keeps that colour. For users without unfiltered_html, saving currently drops the whole preset.

Makes sense, thanks. 👍🏻 That use case alone is a good sell.

I'd be very happy to land things early in the 7.3 cycle

🤞🏻 Appreciate the heads up. Happy to help test stuff!

@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

Thanks @ramonjd and @sirreal for the reviews, extra context etc. Appreciate it.

Shall we get this one merged so that between now and the ongoing work being ready, we can fix or improve the use of CSS colour functions?

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @sirreal is good with this then so am I 😄

Retested in the block editor/frontend for admin and author users. In trunk, the styles are stripped.

Image

@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

If @sirreal is good with this then so am I 😄

Given it was noted the ongoing work didn't have to block this, I'll get this merged. Worst case it's a quick revert.

@aaronrobertshaw
aaronrobertshaw merged commit 5bdc3af into trunk Oct 30, 2026
80 checks passed
@aaronrobertshaw
aaronrobertshaw deleted the fix/kses-css-color-functions branch October 30, 2026 02:31
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 30, 2026
aaronrobertshaw added a commit to aaronrobertshaw/wordpress-develop that referenced this pull request Oct 30, 2026
`safecss_filter_attr()` rejected any declaration containing a color function such as `rgb()`, `hsl()` or `color-mix()`, so styles like a `box-shadow` with an `rgba()` color were stripped.

Color functions are now removed from the test string, innermost first, when their contents are plain color syntax. Anything left over, such as a parenthesis, backslash, comment or unknown function, is still rejected, and the `safecss_filter_attr_allow_css` filter can still reject the declaration.

Synced from WordPress/gutenberg#84213.

Fixes #66387.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants