Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WordPress.Security.NonceVerification.Missing not reported when using filter_input #2299

Open
1 task
kkmuffme opened this issue Jul 10, 2023 · 4 comments
Open
1 task

Comments

@kkmuffme
Copy link

Bug Description

When using filter_input with INPUT_GET or INPUT_POST or INPUT_COOKIE, it's like accessing the $_GET/$_POST superglobals.
Therefore a nonce validation is required.

Minimal Code Snippet

The issue happens when running this command:

./bin/phpcs --config-set installed_paths ../wpcs

... over a file containing this code:

// should report an error
$foo = filter_input( INPUT_POST, 'email', FILTER_SANITIZE_EMAIL );
update_option( 'abc', $foo, false );

// correctly reports an error:
$foo = $_POST['email'];
update_option( 'def', $foo, false );

Error Code

WordPress.Security.NonceVerification.Missing

Environment

Question Answer
PHP version 7.4
PHP_CodeSniffer version 3.7.2
WPCS version 2.3.0
WPCS install type https://github.com/WordPress/WordPress-Coding-Standards#standalone

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.
@kkmuffme
Copy link
Author

Just saw that this was requested by @GaryJones when this rule was added initially: #325 (comment)

While back then someone said that filter_input was discouraged, using filter_input is actually the safer method, compared to (some) WP sanitizing functions, since the INPUT_ is out of scope of userland (e.g. $_POST['foo'] might have been modified somewhere/by any plugin already, while INPUT_POST, 'foo' is guaranteed to be unmodified) and some sanitizers are more secure than what WP can provide (e.g. for host names)

@kkmuffme
Copy link
Author

Same issue also for filter_has_var and filter_input_array

@jrfnl
Copy link
Member

jrfnl commented Oct 30, 2023

@johnstonphilip Please don't spam issues with "+1"'s which don't contribute anything useful to the discussion. You can use the emoji response on the first post for that.

@johnstonphilip
Copy link

I didn't intend to spam. My apologies. I'm just wanting to note that this is a very important issue to me. Thanks, and my apologies again!

lipemat added a commit to lipemat/wp-phpcs that referenced this issue Sep 2, 2024
Expand on the `WordPress.Security.NonceVerification` sniff to detect uses of non-nonce filter_input calls.

@link WordPress/WordPress-Coding-Standards#2299

Task [#1206374008822596]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants