Re-implement safecss_filter_attr() with the CSS token processor#8
Draft
ockham wants to merge 17 commits into
Draft
Re-implement safecss_filter_attr() with the CSS token processor#8ockham wants to merge 17 commits into
ockham wants to merge 17 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sirreal
reviewed
Jul 23, 2026
| * @return int|null Index just past the gradient's closing parenthesis, or | ||
| * null when the gradient is invalid or unclosed. | ||
| */ | ||
| function _safecss_walk_gradient( $tokens, $i, $url_allowed ) { |
Collaborator
There was a problem hiding this comment.
https://drafts.csswg.org/css-syntax/#consume-function
seems like gradients and URLs should be handled by this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Re-implements
safecss_filter_attr()(insrc/wp-includes/kses.php) on top ofWP_CSS_Token_Processor, replacing theexplode( ';' )declaration splitting and regex-based validation with CSS Syntax Level 3 tokenization.For background on the CSS Tokenizer itself, see sirreal#78. This branch stacks on top of that work plus the
WP_HTML_Style_Attribute_Processorcontract.Design
The full design is in
docs/safecss-filter-attr-token-processor-spec.md. Highlights:;inside strings andurl()no longer splits declarations (resolves the long-standing@todo).%[\\\(&=}]|/\*%) and the url/gradient/function-stripping regexes are replaced by token-based validation.url()construct — at any nesting depth — is protocol-checked withwp_kses_bad_protocol(), closing thecalc(url(javascript:…))loophole. This includes payloads inside structurally malformed constructs (bad-url tokens, malformed quotedurl()forms): an identifiable bad-protocol payload is always a hard rejection, while structurally-malformed-but-clean shapes remain soft (filter-rescuable) rejections.safecss_filter_attr_allow_cssfilter is retained:$allow_cssnow comes from token validation; soft rejections remain rescuable, hard rejections (unknown property, bad-protocol url) still bypass the filter as today. Note: the filter's second argument is now the declaration's authored source text rather than the old function-stripped test string.;. All pre-existing kses PHPUnit tests pass unchanged (382 tests intests/phpunit/tests/kses.phpincl. the new ones). Deliberate divergences (all toward strictness, or CSS-correct loosenings like case-insensitiveURL(…)) are enumerated in the spec.Status
🤖 Generated with Claude Code