Making WordPress.org

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#8066 closed enhancement (invalid)

Always sanitize the first parameter of wp_verify_nonce

Reported by: davidperez Owned by:
Priority: normal Milestone:
Component: General Keywords:
Cc:

Description

We ask developers to sanitize and unslash the first parameter of wp_verify_nonce.
Wouldn't it be easier if that piece of repetitive code were not necessary? In the Plugins Team, we often detect that developers forget to do this.

I’m also thinking about the wider community. Many developers may be using wp_verify_nonce incorrectly, without sanitizing it. By handling this automatically, we could prevent security leaks and encourage cleaner code.

This is the correct way to use it right now:

<?php
wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['plugin_slug_nonce_field'] ) ), 'plugin_slug_action_nonce' ) )

And this is the ideal way, with sanitization handled inside the function:

<?php
wp_verify_nonce( $_POST['plugin_slug_nonce_field'], 'plugin_slug_action_nonce' ) )

Does this make it cleaner and more straightforward?

Change History (4)

This ticket was mentioned in ​Slack in #core by davidperez. ​View the logs.


15 months ago

#2 @rollybueno
15 months ago

Hey @davidperez, I think this should be under core trac since it's on the pluggable in WP Core, not meta..

#3 @davidperez
15 months ago

  • Resolution → wontfix
  • Status new → closed

#4 @Otto42
15 months ago

  • Resolution wontfix → invalid
Note: See TracTickets for help on using tickets.