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

Cherry-pick #301 into trunk #44667

Merged
merged 1 commit into from Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-292-sync-orders-csrf
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Adds a nonce check to the HPOS order sync tool.
Expand Up @@ -11,6 +11,7 @@
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
use Automattic\WooCommerce\Utilities\PluginUtil;
use WC_Admin_Settings;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -339,10 +340,17 @@ private function sync_now() {
return;
}

if ( filter_input( INPUT_GET, self::SYNC_QUERY_ARG, FILTER_VALIDATE_BOOLEAN ) ) {
$this->data_cleanup->toggle_flag( false );
$this->batch_processing_controller->enqueue_processor( DataSynchronizer::class );
if ( ! filter_input( INPUT_GET, self::SYNC_QUERY_ARG, FILTER_VALIDATE_BOOLEAN ) ) {
return;
}

if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ?? '' ) ), 'hpos-sync-now' ) ) {
WC_Admin_Settings::add_error( esc_html__( 'Unable to start synchronization. The link you followed may have expired.', 'woocommerce' ) );
return;
}

$this->data_cleanup->toggle_flag( false );
$this->batch_processing_controller->enqueue_processor( DataSynchronizer::class );
}

/**
Expand Down Expand Up @@ -520,11 +528,14 @@ private function get_hpos_setting_for_sync() {
$orders_pending_sync_count
);
} elseif ( $sync_is_pending ) {
$sync_now_url = add_query_arg(
array(
self::SYNC_QUERY_ARG => true,
$sync_now_url = wp_nonce_url(
add_query_arg(
array(
self::SYNC_QUERY_ARG => true,
),
wc_get_container()->get( FeaturesController::class )->get_features_page_url()
),
wc_get_container()->get( FeaturesController::class )->get_features_page_url()
'hpos-sync-now'
);

if ( ! $is_dangerous ) {
Expand Down