Skip to content

Security/ValidatedSanitizedInput: add XML documentation#2698

Open
rodrigoprimo wants to merge 3 commits into
WordPress:developfrom
rodrigoprimo:docs-validated-sanitized-input
Open

Security/ValidatedSanitizedInput: add XML documentation#2698
rodrigoprimo wants to merge 3 commits into
WordPress:developfrom
rodrigoprimo:docs-validated-sanitized-input

Conversation

@rodrigoprimo

@rodrigoprimo rodrigoprimo commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds XML documentation for the WordPress.Security.ValidatedSanitizedInput sniff.

The documentation is based on the work started by @rooh-wp311 in #2587. I used the original commit and, in a separate commit, made the following changes to the original version of the documentation:

  • 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.

I suggest squashing the two commits before merging. I'm opening the PR without doing that to make it easier to tell my changes apart from the original changes.

Suggested changelog entry

N/A

Related issues/external references

Related to: #1722
Supersedes: #2587
Closes #2587

rvasudev-ipa and others added 2 commits February 9, 2026 17:48
- 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.

@jrfnl jrfnl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up @rodrigoprimo ! I've skimmed through it (my brain is fried), but left some remarks anyway. Hope this helps.

Comment on lines +11 to +27
<standard>
<![CDATA[
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.
]]>
</standard>
<code_comparison>
<code title="Valid: No superglobal in string interpolation.">
<![CDATA[
// No superglobal in string interpolation.
]]>
</code>
<code title="Invalid: Superglobal used in string interpolation.">
<![CDATA[
echo "Hello <em>{$_GET['name']}</em>";
]]>
</code>
</code_comparison>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about moving this block to the end ? The other sections more logically follow the intro. This is kind of the "odd one out", making it more logic to have it at the end IMO.

Comment on lines +17 to +19
<code title="Valid: No superglobal in string interpolation.">
<![CDATA[
// No superglobal in string interpolation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about having an example of how to do this properly instead ?

All input must be sanitized to remove potentially malicious content before it is used.
]]>
</standard>
<code_comparison>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a must-have, but it may simplify the example code a little to use $_ENV instead (which doesn't need unslashing) ?
Or maybe having an example with both $_POST as well as $_ENV would help users ?

<![CDATA[
if ( <em>isset( $_POST['name'] )</em> ) {
$name = sanitize_text_field(
wp_unslash( <em>$_POST['name']</em> )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure these <em>'s are needed - the point of the example is the isset(), isn't it ? If nothing else, it would make the <em> more consistent across the examples.

>
<standard>
<![CDATA[
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at the original PR, I don't think it's a bad thing to mention that doing this is about security and to mention a couple of examples (not XSS, which was mentioned in the original PR as that's wrong, but SQL injection and CSRF sound like good pointers for people if they want to understand better why we enforce this).

@rodrigoprimo

Copy link
Copy Markdown
Contributor Author

Thanks for your review, @jrfnl. I pushed a new commit applying the changes you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants