Add escaping and sanitize the output of custom colors CSS into the Twentyseventeen theme.#8108
Add escaping and sanitize the output of custom colors CSS into the Twentyseventeen theme.#8108viralsampat-multidots wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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. |
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. |
sabernhardt
left a comment
There was a problem hiding this comment.
Please remove esc_attr() and the extra space after the semicolon.
I should note that the preference between wp_strip_all_tags() and esc_html() is still questionable, but let's keep wp_strip_all_tags() in this PR for now.
| ?> | ||
| <style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>> | ||
| <?php echo twentyseventeen_custom_colors_css(); ?> | ||
| <style type="text/css" id="custom-theme-colors" <?php echo esc_attr( $customize_preview_data_hue ); ?>> |
There was a problem hiding this comment.
| <style type="text/css" id="custom-theme-colors" <?php echo esc_attr( $customize_preview_data_hue ); ?>> | |
| <style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>> |
The $customize_preview_data_hue variable should not be escaped:
<style type="text/css" id="custom-theme-colors" data-hue="356">
It is either an empty string or an attribute/value pair like data-hue="356". The absint() function ensures that the hue value is always an integer.
I would also like to move the space before the data-hue attribute inside the $customize_preview_data_hue variable, and the type attribute is unnecessary, but those changes are not important.
if ( is_customize_preview() ) {
$customize_preview_data_hue = ' data-hue="' . $hue . '"';
}
?>
<style id="custom-theme-colors"<?php echo $customize_preview_data_hue; ?>>
| <style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>> | ||
| <?php echo twentyseventeen_custom_colors_css(); ?> | ||
| <style type="text/css" id="custom-theme-colors" <?php echo esc_attr( $customize_preview_data_hue ); ?>> | ||
| <?php echo wp_strip_all_tags( twentyseventeen_custom_colors_css() ); ?> |
There was a problem hiding this comment.
| <?php echo wp_strip_all_tags( twentyseventeen_custom_colors_css() ); ?> | |
| <?php echo wp_strip_all_tags( twentyseventeen_custom_colors_css() ); ?> |
The PHP coding standards GitHub action caught that there are two spaces after the semicolon when it should only be one.
Trac ticket: https://core.trac.wordpress.org/ticket/62798
This PR adds proper sanitization to the custom colors CSS output in the Twenty Seventeen theme. The twentyseventeen_custom_colors_css() function's output is filterable and currently outputs unsanitized content.
The PR wraps outputs with wp_strip_all_tags() to ensure only CSS is included, preventing potential injection of unwanted HTML through filters.
Thanks,