KSES: Allow CSS anchor positioning in safecss_filter_attr()#12337
KSES: Allow CSS anchor positioning in safecss_filter_attr()#12337dhrupo wants to merge 1 commit into
Conversation
Add the CSS anchor positioning properties (anchor-name, anchor-scope, position-anchor, position-area, position-try, position-try-fallbacks, position-try-order, position-visibility) to the safe_style_css allowlist, and allow the anchor() and anchor-size() functions in declaration values. Allowlisting the properties alone is not enough: anchor positioning is driven by the anchor() and anchor-size() functions used in inset and sizing properties (e.g. top: anchor(--foo bottom)). Without those functions in the allowlist, safecss_filter_attr() strips any declaration using them, so the feature remains unusable. The functions are handled the same way as the existing var()/calc()/clamp() allowlist, so unknown functions such as expression() are still stripped. Adds regression tests covering the properties, the anchor()/anchor-size() functions (including nesting inside calc()), and that an unknown function is still rejected. Fixes #64972.
|
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. |
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
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. |
Summary
Allow CSS anchor positioning in
safecss_filter_attr()so it is no longer stripped fromstyleattributes filtered through KSES.Trac ticket: https://core.trac.wordpress.org/ticket/64972
Problem
On trunk, every anchor positioning declaration is stripped:
This is two separate gaps:
safe_style_cssallowlist.anchor()andanchor-size()functions are not in the allowlist of CSS functions.safecss_filter_attr()rejects any declaration whose value still contains a function call after the known functions (var,calc,min,max,minmax,clamp,repeat) are removed.Why a properties-only fix is not enough
There is an existing PR, #11419, which adds the anchor positioning properties only. That is necessary but not sufficient: anchor positioning is driven by the
anchor()andanchor-size()functions used in standard inset and sizing properties (e.g.top: anchor(--tooltip bottom),width: anchor-size(--tooltip width)). Because those functions are not allowlisted, such declarations are still stripped, so the feature remains unusable after #11419, and its test only exercises simple values such asposition-area: topso the gap is not caught.This PR is a superset of #11419: it adds the same properties and the
anchor()/anchor-size()functions, with tests that cover the function usage.Changes
safe_style_cssallowlist:anchor-name,anchor-scope,position-anchor,position-area,position-try,position-try-fallbacks,position-try-order,position-visibility.anchorandanchor-sizeto the allowed CSS functions, handled the same way as the existingvar()/calc()/clamp()allowlist. Unknown functions such asexpression()are still stripped, so sanitization is not weakened.@sincedocblock.anchor()/anchor-size()functions (including nesting insidecalc()), and that an unknown function is still rejected.Testing instructions
Or manually:
Relationship to #11419
This supersedes #11419, which only allowlists the properties. If preferred, the property list here could instead be merged into #11419 and this PR reduced to the function allowlist — happy to coordinate either way.
Use of AI Tools
wordpress-developDocker environment, and verified with PHPUnit and PHPCS by me.