File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -296,16 +296,18 @@ protected function __construct() {
296296 );
297297
298298 // POST handler
299- if (
300- isset ( $ _SERVER ['REQUEST_METHOD ' ] ) && 'POST ' === strtoupper ( sanitize_text_field ( wp_unslash ( $ _SERVER ['REQUEST_METHOD ' ] ) ) )
301- &&
302- isset ( $ _POST ['action ' ] ) && 'grunion-contact-form ' === $ _POST ['action ' ] // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verification should happen when hook fires.
303- &&
304- isset ( $ _POST ['contact-form-id ' ] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- no site changes
305- ) {
306- add_action ( 'template_redirect ' , array ( $ this , 'process_form_submission ' ) );
307- }
308-
299+ if (
300+ isset ( $ _SERVER ['REQUEST_METHOD ' ] ) && 'POST ' === strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['REQUEST_METHOD ' ] ) ) )
301+ && isset ( $ _POST ['action ' ] ) && 'grunion-contact-form ' === sanitize_text_field ( wp_unslash ( $ _POST ['action ' ] ) )
302+ && isset ( $ _POST ['contact-form-id ' ] )
303+ ) {
304+ // Verify the form nonce early to avoid attaching handlers for forged requests.
305+ if ( ! empty ( $ _POST ['grunion_contact_form_nonce ' ] ) && wp_verify_nonce ( wp_unslash ( $ _POST ['grunion_contact_form_nonce ' ] ), 'grunion-contact-form ' ) ) {
306+ add_action ( 'template_redirect ' , array ( $ this , 'process_form_submission ' ) );
307+ } else {
308+ // Invalid nonce — do not attach handler.
309+ }
310+ }
309311 /*
310312 * Can be dequeued by placing the following in wp-content/themes/yourtheme/functions.php
311313 *
You can’t perform that action at this time.
0 commit comments