WordPress / WordPress/WordPress-Coding-Standards

False positive: Allow trimming input before sanitizing

Open
#2,180 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Focus: Security Status: Awaiting feedback Status: Invalid
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Sometimes, an input is flagged as not sanitized if we trim it:

$foo = absint( $_GET['foo'] ); // OK.

$foo = absint( trim( $_GET['foo'] ) ); // InputNotSanitized.
$foo = absint( ltrim( $_GET['foo'] ) ); // InputNotSanitized.
$foo = absint( rtrim( $_GET['foo'] ) ); // InputNotSanitized.

I believe trimming should be accepted before sanitizing an input.

Maybe we could add ltrim, rtrim, and trim as a trimmingFunctions array and allow them here? https://github.com/WordPress/WordPress-Coding-Standards/blob/2ac765f2b0ae653efef9f5dda74cd2324f3abe78/WordPress/Sniff.php#L1852

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read WordPress/WordPress-Coding-Standards/blob/2ac765f2b0ae653efef9f5dda74cd2324f3abe78/WordPress/Sniff.php around line 1852, then reproduce the absint examples from the issue. The work is done when trim(), ltrim(), and rtrim() before sanitizing no longer produce InputNotSanitized.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.