From 6b078b9e910fcd111e3a6b276d46d1d4469f506f Mon Sep 17 00:00:00 2001 From: Akshay Urankar <101685739+akshayurankar48@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:01:17 +0530 Subject: [PATCH 1/4] fix: strengthen nonce verification across plugin - Replace generic 'ajax_nonce' action with 'bsf_meta_box_ajax_nonce' to prevent cross-plugin nonce collision - Replace basename(__FILE__) nonce action with explicit 'bsf_meta_box_nonce_action' string - Gate bsf_reset_options() behind $nonce_verified flag so it only executes after a per-option nonce check passes - Sanitize nonce and option values in reset handler Fixes #220 --- admin/index.php | 44 ++++++++++++++++++++++++++++---------------- init.php | 12 ++++++------ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/admin/index.php b/admin/index.php index 7258714..c03e46d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1167,43 +1167,55 @@ function display_status( $status ) { } } if ( isset( $_GET['action'] ) ) { - if ( 'reset' == esc_attr( $_GET['action'] ) && isset( $_GET['nonce'] ) && current_user_can( 'manage_options' ) ) { - $option_to_reset = esc_attr( $_GET['options'] ); - if ( 'review' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_item_nonce' ) ) { + if ( 'reset' == sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['nonce'] ) && current_user_can( 'manage_options' ) ) { + $option_to_reset = sanitize_text_field( wp_unslash( $_GET['options'] ) ); + $nonce_value = sanitize_text_field( wp_unslash( $_GET['nonce'] ) ); + $nonce_verified = false; + + if ( 'review' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_item_nonce' ) ) { delete_option( 'bsf_review' ); + $nonce_verified = true; } - if ( 'event' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_event_nonce' ) ) { + if ( 'event' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_event_nonce' ) ) { delete_option( 'bsf_event' ); + $nonce_verified = true; } - if ( 'person' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_person_nonce' ) ) { + if ( 'person' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_person_nonce' ) ) { delete_option( 'bsf_person' ); + $nonce_verified = true; } - - if ( 'product' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_product_nonce' ) ) { + if ( 'product' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_product_nonce' ) ) { delete_option( 'bsf_product' ); + $nonce_verified = true; } - if ( 'recipe' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_recipe_nonce' ) ) { + if ( 'recipe' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_recipe_nonce' ) ) { delete_option( 'bsf_recipe' ); + $nonce_verified = true; } - if ( 'software' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_software_nonce' ) ) { + if ( 'software' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_software_nonce' ) ) { delete_option( 'bsf_software' ); + $nonce_verified = true; } - if ( 'video' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_video_nonce' ) ) { + if ( 'video' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_video_nonce' ) ) { delete_option( 'bsf_video' ); + $nonce_verified = true; } - - if ( 'article' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_article_nonce' ) ) { + if ( 'article' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_article_nonce' ) ) { delete_option( 'bsf_article' ); + $nonce_verified = true; } - if ( 'service' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_service_nonce' ) ) { + if ( 'service' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_service_nonce' ) ) { delete_option( 'bsf_service' ); + $nonce_verified = true; } - - if ( 'color' == $option_to_reset && wp_verify_nonce( $_GET['nonce'], 'aiosrs_color_nonce' ) ) { + if ( 'color' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_color_nonce' ) ) { delete_option( 'bsf_custom' ); + $nonce_verified = true; } - bsf_reset_options( $option_to_reset ); + if ( $nonce_verified ) { + bsf_reset_options( $option_to_reset ); + } } } /** diff --git a/init.php b/init.php index 8d5204e..e0a202c 100644 --- a/init.php +++ b/init.php @@ -179,7 +179,7 @@ public function add_for_page_template( $display, $meta_box ) { public function show() { global $post; // Use nonce for verification. - echo ''; + echo ''; echo '