[wp-trac] [WordPress Trac] #43215: Allow wp_kses to pass allowed CSS properties

WordPress Trac noreply at wordpress.org
Thu Jan 16 07:13:39 UTC 2025


#43215: Allow wp_kses to pass allowed CSS properties
-----------------------------+------------------------------
 Reporter:  mclaurent        |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Security         |     Version:  4.9.2
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by davidtheplumber):

 Register a unique hook for safe_style_css specifically for your use case:


 {{{
 add_filter('safe_style_css', 'custom_safe_style_css', 10, 1);

 function custom_safe_style_css($styles) {
     if (did_action('custom_safe_style_css')) {
         $styles[] = 'display';
         $styles[] = 'visibility';
     }
     return $styles;
 }

 $allowed_output_html = array(
     'script' => array(),
     'noscript' => array(),
     'iframe' => array(
         'src' => array(),
         'width' => array(),
         'height' => array(),
         'style' => array(),
     ),
 );

 $google_tag_manager_noscript = <<<ENDSTRING
 <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=123"
     height="0" width="0"
 style="display:none;visibility:hidden"></iframe></noscript>
 ENDSTRING;

 // Use custom hook only for this execution
 do_action('custom_safe_style_css');
 echo wp_kses($google_tag_manager_noscript, $allowed_output_html,
 $allowed_output_protocol);
 remove_filter('safe_style_css', 'custom_safe_style_css');
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43215#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list