WordPress / WordPress/WordPress-Coding-Standards

Add some admin bar methods to the printing functions

Open
#473 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Focus: Security Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining WordPress_Sniff::$printingFunctions and the admin_bar_menu hook usage described in the issue. Investigate how add_menu and add_node could trigger warnings for unescaped title data; done means the relevant calls are recognized and covered by the sniff's warning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
security, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.