Skip to content

fix sanitization for style-engine declarations#42968

Closed
aristath wants to merge 3 commits into
trunkfrom
fix/42948
Closed

fix sanitization for style-engine declarations#42968
aristath wants to merge 3 commits into
trunkfrom
fix/42948

Conversation

@aristath

@aristath aristath commented Aug 4, 2022

Copy link
Copy Markdown
Member

What?

Fixes #42948

This PR is a partial from #42893, specifically the part of that PR regarding the sanitization of CSS delcarations in the style engine.

Why?

Some things need to bypass the safecss_filter_attr call, and the sanitization of values is further improved here.

Comment thread packages/style-engine/class-wp-style-engine-css-declarations.php
Comment thread packages/style-engine/class-wp-style-engine-css-declarations.php
Comment thread packages/style-engine/class-wp-style-engine-css-rule.php Outdated
Comment on lines +133 to +143
if (
0 === strpos( $property, '--' ) || // Account for CSS variables.
( 'display' === $property && 'none' !== $value ) || // Account for "display" when the value is not "none".
0 === strpos( $value, 'min(' ) || // Account for min() values.
0 === strpos( $value, 'max(' ) || // Account for max() values.
0 === strpos( $value, 'clamp(' ) // Account for clamp() values.
) {
$declarations_output .= "{$indent}{$property}:{$spacer}{$value};$suffix";
continue;
}
$filtered_declaration = safecss_filter_attr( "{$property}:{$spacer}{$value};" );

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.

Maybe we can use safecss_filter_attr_allow_css filter and regex from 55966. Then we can remove the compat function after the core patch is merged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, that's a good point. Ideally we'd be deferring as much as possible to safecss_filter_attr rather than adding too much extra handling in the style engine directly.

I've opened up a potential alternative PR in #43004 to play with this idea.

@andrewserong

Copy link
Copy Markdown
Contributor

Thanks for picking this one up @aristath and digging in! I think @Mamaduka raises a good point about seeing if we can use the proposed update in core filtering to hopefully sidetrack having to include too much logic directly in the style engine for the additional CSS functions. I've had a go at this in #43004 as a potential alternative.

@aristath

aristath commented Aug 9, 2022

Copy link
Copy Markdown
Member Author

no longer needed after #43004 was merged, closing.

@aristath aristath closed this Aug 9, 2022
@johnbillion johnbillion deleted the fix/42948 branch April 22, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🗄 Closed / not merged

Development

Successfully merging this pull request may close these issues.

1.3.9: clamp() is no longer recognized in “contentSize” or “wideSize” in theme.json

4 participants