WordPress / WordPress/WordPress-Coding-Standards
Add some admin bar methods to the printing functions
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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