Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions WordPress/Docs/Security/PluginMenuSlugStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0"?>
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
title="Plugin Menu Slug"
>
<standard>
<![CDATA[
Wordpress functions that can be used to add pages to the WP Admin menu should not include `__FILE__` for the menu slug (or parent menu slug) parameter to avoid revealing system paths.
]]>
</standard>
<code_comparison>
<code title="Valid: Slug does not include `__FILE__`.">
<![CDATA[
add_menu_page(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is worth adding a second valid/invalid example with add_submenu_page() as this is the only function that has a different signature than the others, and where __FILE__ should not be used for the parent_slug as well as the menu_slug?

There is no need to create new <code> blocks, you can add the new example in the <code> blocks that already exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigoprimo Good call. I added add_submenu_page() examples to the existing code blocks with similar __FILE__ examples.

'My Plugin Main Page',
'My Plugin',
'manage_options',
<em>'my-plugin-main'</em>,
'my_plugin_main_page'
);

add_submenu_page(
<em>'my_plugin_main_page'</em>,
'My Plugin Subpage',
'Subpage',
'manage_options',
'my-plugin-subpage',
'my_plugin_subpage'
);
]]>
</code>
<code title="Invalid: Slug includes `__FILE__`.">
<![CDATA[
add_menu_page(
'My Plugin Main Page',
'My Plugin',
'manage_options',
<em>__FILE__ . </em>'my-plugin-subpage',
'my_plugin_main_page'
);

add_submenu_page(
<em>__FILE__ . </em>'my_plugin_main_page',
'My Plugin Subpage',
'Subpage',
'manage_options',
'my-plugin-subpage',
'my_plugin_subpage'
);
]]>
</code>
</code_comparison>
</documentation>
Loading