Skip to content

Add some admin bar methods to the printing functions #473

@johnbillion

Description

@johnbillion

Passing unescaped data to the title property of WP_Admin_Bar::add_menu() is unsafe, because it's not escaped on output in the menu. Example:

add_action( 'admin_bar_menu', function( WP_Admin_Bar $wp_admin_bar ) {

    $title = 'Hello world<script>alert(document.cookie);</script>';
    $wp_admin_bar->add_menu( array(
        'id'    => 'wpcs-test',
        'title' => $title,
        'href'  => '#',
    ) );

} );

It would be nice if the following could be added as printing functions, so they trigger a warning when unescaped data is passed to them:

  • $wp_admin_bar->add_menu
  • $wp_admin_bar->add_node

I tried adding these to the WordPress_Sniff::$printingFunctions property array, but it didn't work, so this might not even be possible. The use of a specific variable name is weird, but it's a common one to use for the parameter passed to callback functions hooked onto the admin_bar_menu hook.

Any ideas about how this could be achieved?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions