Skip to content

Commit 7737100

Browse files
authored
Add documentation for sniff WordPress.Security.PluginMenuSlug (#2592)
Describes check for __FILE__ in plugin menu slugs.
1 parent 8e14560 commit 7737100

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Plugin Menu Slug"
5+
>
6+
<standard>
7+
<![CDATA[
8+
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.
9+
]]>
10+
</standard>
11+
<code_comparison>
12+
<code title="Valid: Slug does not include `__FILE__`.">
13+
<![CDATA[
14+
add_menu_page(
15+
'My Plugin Main Page',
16+
'My Plugin',
17+
'manage_options',
18+
<em>'my-plugin-main'</em>,
19+
'my_plugin_main_page'
20+
);
21+
22+
add_submenu_page(
23+
<em>'my_plugin_main_page'</em>,
24+
'My Plugin Subpage',
25+
'Subpage',
26+
'manage_options',
27+
'my-plugin-subpage',
28+
'my_plugin_subpage'
29+
);
30+
]]>
31+
</code>
32+
<code title="Invalid: Slug includes `__FILE__`.">
33+
<![CDATA[
34+
add_menu_page(
35+
'My Plugin Main Page',
36+
'My Plugin',
37+
'manage_options',
38+
<em>__FILE__</em>,
39+
'my_plugin_main_page'
40+
);
41+
42+
add_submenu_page(
43+
<em>__FILE__</em> . 'my_plugin_main_page',
44+
'My Plugin Subpage',
45+
'Subpage',
46+
'manage_options',
47+
'my-plugin-subpage',
48+
'my_plugin_subpage'
49+
);
50+
]]>
51+
</code>
52+
</code_comparison>
53+
</documentation>

0 commit comments

Comments
 (0)