You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve ValidatedSanitizedInput documentation based on PR review
- Add introductory standard block explaining what the sniff checks,
using language that avoids the overloaded term "validated".
- Rewrite standard descriptions to explain why each rule exists.
- Add <em> tags to highlight key parts in code examples.
- Remove specific mention of XSS as the attack vector.
- Focus each section on its specific error without mixing concerns.
- List which superglobals require wp_unslash() in MissingUnslash
section.
- Use varied superglobals and sanitizing functions across code
examples.
- Keep code examples within 48-character column width.
Copy file name to clipboardExpand all lines: WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml
+35-28Lines changed: 35 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -5,90 +5,97 @@
5
5
>
6
6
<standard>
7
7
<![CDATA[
8
-
All user input data ($_POST, $_GET, $_REQUEST, $_SERVER, $_COOKIE, $_FILES, $_SESSION, $_ENV) must be validated, unslashed, and sanitized before use to prevent security vulnerabilities like XSS, SQL injection, and code injection attacks.
9
-
10
-
Validation ensures the input key exists (using isset(), empty(), array_key_exists(), or null coalescing operators). Unslashing removes WordPress's automatic backslashes using wp_unslash() or similar functions. Sanitization cleans the data using appropriate functions like sanitize_text_field(), absint(), etc.
8
+
Superglobals ($_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_REQUEST, $_SERVER, $_SESSION) must be properly handled before use: array keys must be checked for existence and values must be sanitized.
11
9
]]>
12
10
</standard>
13
11
<standard>
14
12
<![CDATA[
15
-
String interpolation with superglobals requires validation and sanitization. Using $_POST, $_GET, etc. directly in strings can lead to XSS attacks if the input contains malicious code.
13
+
Superglobals must not be used directly in string interpolation or heredocs. The array key might not exist, or its value could contain malicious content that gets included in the string without sanitization.
16
14
]]>
17
15
</standard>
18
16
<code_comparison>
19
-
<codetitle="Valid: String interpolation with proper validation and sanitization.">
17
+
<codetitle="Valid: No superglobal in string interpolation.">
<codetitle="Invalid: String interpolation without validation or sanitization.">
22
+
<codetitle="Invalid: Superglobal used in string interpolation.">
28
23
<![CDATA[
29
-
echo "Hello {$_POST['name']}";
24
+
echo "Hello <em>{$_GET['name']}</em>";
30
25
]]>
31
26
</code>
32
27
</code_comparison>
33
28
<standard>
34
29
<![CDATA[
35
-
All superglobal array access must be validated to ensure the key exists before use. This prevents undefined index notices and potential security issues.
30
+
Superglobal array keys must be checked for existence before use. Accessing a key that does not exist can lead to unexpected behavior.
36
31
]]>
37
32
</standard>
38
33
<code_comparison>
39
34
<codetitle="Valid: Input is validated before use.">
<codetitle="Invalid: Input validated but not sanitized.">
66
+
<codetitle="Invalid: Input used without sanitization.">
66
67
<![CDATA[
67
-
if ( isset( $_POST['text'] ) ) {
68
-
$text = wp_unslash( $_POST['text'] );
68
+
if ( isset( $_POST['email'] ) ) {
69
+
$email = wp_unslash(
70
+
<em>$_POST['email']</em>
71
+
);
69
72
}
70
73
]]>
71
74
</code>
72
75
</code_comparison>
73
76
<standard>
74
77
<![CDATA[
75
-
WordPress automatically adds backslashes to certain superglobals. These must be removed using wp_unslash() or similar functions before sanitization to prevent double-escaping issues.
78
+
WordPress adds slashes to $_COOKIE, $_GET, $_POST, $_REQUEST, and $_SERVER elements. These must be passed through an unslashing function before sanitization to ensure the data is processed correctly.
76
79
]]>
77
80
</standard>
78
81
<code_comparison>
79
82
<codetitle="Valid: Input is unslashed before sanitization.">
0 commit comments