WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

filter_input() doesn't mean variable is sanitized

Open allan23 opened this issue 9 years ago • 3 comments

filter_input() is listed as an escaping function. However if the third parameter isn't set, then no sanitization takes place.

Example: URL: http://test.dev/?test=%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E

echo filter_input( INPUT_GET, 'test' );

vs.

echo filter_input( INPUT_GET, 'test', FILTER_SANITIZE_STRING );

Should detection of filter_input require manual inspection or is it possible to check if the third parameter is set?

allan23 avatar Jan 19 '16 12:01 allan23

It would be possible to detect whether the third parameter was supplied, if anyone would like to work up a patch.

JDGrimes avatar Jan 19 '16 14:01 JDGrimes

A side note: I think that probably the filter_input() function should be flagged by the WordPress.VIP.SuperGlobalInputUsage sniff.

JDGrimes avatar Jan 23 '16 21:01 JDGrimes

I think we need a separate sniff to check for correct usage of the filter_...() functions. This does not have to be combined with an existing sniff.

jrfnl avatar Mar 31 '19 07:03 jrfnl