diff --git a/woocommerce/changelog.txt b/woocommerce/changelog.txt index cf756e266..832828778 100644 --- a/woocommerce/changelog.txt +++ b/woocommerce/changelog.txt @@ -2,6 +2,7 @@ 2026.nn.nn - version 6.2.5 * Fix - "event is not a function" error on My Payment Methods page +* Fix - Add additional nonce and permission checks 2026.08.19 - version 6.2.4 * Security - Hardened capability checks around the payment token editor's admin functionality diff --git a/woocommerce/class-sv-wc-admin-notice-handler.php b/woocommerce/class-sv-wc-admin-notice-handler.php index 938fa098f..aa8dc6077 100644 --- a/woocommerce/class-sv-wc-admin-notice-handler.php +++ b/woocommerce/class-sv-wc-admin-notice-handler.php @@ -230,16 +230,30 @@ public function render_admin_notice( $message, $message_id, $params = array() ) } echo sprintf( - '

%5$s

', + '

%5$s

', esc_attr( implode( ' ', $classes ) ), esc_attr( $this->get_plugin()->get_id() ), esc_attr( $message_id ), ( ! $params['is_visible'] ) ? 'style="display:none;"' : '', - wp_kses_post( $message ) + wp_kses_post( $message ), + esc_attr( wp_create_nonce( $this->get_dismiss_notice_nonce_action() ) ) ); } + /** + * Gets the nonce action used to authorize dismissing notices for this plugin. + * + * @since 6.2.5 + * + * @return string + */ + protected function get_dismiss_notice_nonce_action() : string { + + return 'wc_plugin_framework_' . $this->get_plugin()->get_id() . '_dismiss_notice'; + } + + /** * Render the javascript to handle the notice "dismiss" functionality * @@ -273,7 +287,8 @@ public function render_admin_notice_js() { log_dismissed_notice( $( $notice ).data( 'plugin-id' ), - $( $notice ).data( 'message-id' ) + $( $notice ).data( 'message-id' ), + $( $notice ).data( 'nonce' ) ); } ); @@ -287,20 +302,22 @@ public function render_admin_notice_js() { log_dismissed_notice( $( $notice ).data( 'plugin-id' ), - $( $notice ).data( 'message-id' ) + $( $notice ).data( 'message-id' ), + $( $notice ).data( 'nonce' ) ); $( $notice ).fadeOut(); } ); - function log_dismissed_notice( pluginID, messageID ) { + function log_dismissed_notice( pluginID, messageID, nonce ) { - $.get( + $.post( ajaxurl, { action: 'wc_plugin_framework_' + pluginID + '_dismiss_notice', - messageid: messageID + messageid: messageID, + nonce: nonce } ); } @@ -419,8 +436,19 @@ public function get_dismissed_notices( $user_id = null ) { */ public function handle_dismiss_notice() { - $this->dismiss_notice( $_REQUEST['messageid'] ); + check_ajax_referer( $this->get_dismiss_notice_nonce_action(), 'nonce' ); + + if ( ! current_user_can( 'manage_woocommerce' ) ) { + wp_send_json_error( null, 403 ); + } + + if ( empty( $_REQUEST['messageid'] ) || ! is_string( $_REQUEST['messageid'] ) ) { + wp_send_json_error( null, 400 ); + } + + $this->dismiss_notice( sanitize_text_field( wp_unslash( $_REQUEST['messageid'] ) ) ); + wp_send_json_success(); } diff --git a/woocommerce/utilities/class-sv-wp-job-batch-handler.php b/woocommerce/utilities/class-sv-wp-job-batch-handler.php index 2dc89060e..8e75622a3 100644 --- a/woocommerce/utilities/class-sv-wp-job-batch-handler.php +++ b/woocommerce/utilities/class-sv-wp-job-batch-handler.php @@ -87,6 +87,21 @@ protected function add_hooks() { add_action( 'wp_ajax_' . $this->get_job_handler()->get_identifier() . '_cancel_job', array( $this, 'ajax_cancel_job' ) ); } + /** + * Gets the capability required to process or cancel jobs via AJAX. + * + * Child classes can override this to require a different capability. + * + * @since 6.2.5 + * + * @return string + */ + protected function get_required_capability() : string { + + return 'manage_woocommerce'; + } + + /** * Gets the name of the script handle. * @@ -185,6 +200,10 @@ public function ajax_process_batch() { check_ajax_referer( $this->get_job_handler()->get_identifier() . '_process_batch', 'security' ); + if ( ! current_user_can( $this->get_required_capability() ) ) { + wp_send_json_error( null, 403 ); + } + if ( empty( $_POST['job_id'] ) ) { return; } @@ -219,6 +238,10 @@ public function ajax_cancel_job() { check_ajax_referer( $this->get_job_handler()->get_identifier() . '_cancel_job', 'security' ); + if ( ! current_user_can( $this->get_required_capability() ) ) { + wp_send_json_error( null, 403 ); + } + if ( empty( $_POST['job_id'] ) ) { return; }