Skip to content

KSES: Allow filter function values in inline styles. - #13039

Open
jigneshbhavani wants to merge 1 commit into
WordPress:trunkfrom
jigneshbhavani:fix/kses-filter-function-values
Open

KSES: Allow filter function values in inline styles.#13039
jigneshbhavani wants to merge 1 commit into
WordPress:trunkfrom
jigneshbhavani:fix/kses-filter-function-values

Conversation

@jigneshbhavani

Copy link
Copy Markdown

filter has been in the safecss_filter_attr() property allowlist since [52049], and
[55564] made url() values survive, but the CSS filter functions were never added to the
function-stripping expression at wp-includes/kses.php:3018. A declaration using one still
contains a ( when it reaches the check below it, so it is dropped in full and the property
is unusable in its canonical form for anyone without unfiltered_html.

Measured on trunk at [63180], PHP 8.3:

Declaration Before After
filter: blur(5px) dropped kept
filter: brightness(0.4) dropped kept
filter: contrast(200%) dropped kept
filter: drop-shadow(16px 16px 20px blue) dropped kept
filter: grayscale(50%) dropped kept
filter: hue-rotate(90deg) kept kept
filter: invert(75%) dropped kept
filter: opacity(25%) dropped kept
filter: saturate(30%) dropped kept
filter: sepia(60%) dropped kept
filter: blur(5px) brightness(0.4) dropped kept
filter: url(#svg-blur) kept kept
filter: none kept kept

hue-rotate() already passed, but not by design: [63180] added rotate for the transform
functions and \brotate( matches inside hue-rotate(90deg) because the hyphen is a word
boundary, leaving filter: hue- in the test string. It is now matched by its own name.

This is the same change [63180] made for the transform and basic shape functions. The value
is still re-emitted from the original declaration, url() values still go through
wp_kses_bad_protocol(), and the test string check is unchanged, so the security model is
the same.

Not in scope: backdrop-filter is not allowlisted at all, and the colour functions rgb(),
rgba(), hsl() and color-mix() are dropped everywhere, which is #56391.

Testing

12 of the new cases fail on trunk without the kses.php change:

1) Tests_Kses::test_safecss_filter_attr with data set #138 ('filter: blur(5px)', 'filter: blur(5px)')
...
FAILURES!
Tests: 163, Assertions: 163, Failures: 12.

With the patch the full kses group is green, 487 tests / 1562 assertions, and phpcs
passes on both changed files.

Trac ticket: https://core.trac.wordpress.org/ticket/65871

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Drafting this description and a first pass at the test cases. I measured the
before and after behaviour myself, confirmed the tests fail without the patch, ran the
kses group and phpcs, and I take responsibility for the change.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

The `filter` property has been allowlisted since [52049], and [55564] made
`url()` values survive, but the CSS filter functions were never added to the
function-stripping expression, so every functional value was dropped in full.
`hue-rotate()` was the sole exception, and only because `\brotate(` matches
inside it after the transform functions were added in [63180].

Follow-up to [63180].

See #65871.
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props bejignesh.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant