Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/woosquare/admin/modules/square-payments/class-woosquare-payments.php
+++ b/woosquare/admin/modules/square-payments/class-woosquare-payments.php
@@ -422,9 +422,7 @@
* Processes the checkout for a terminal payment using Square's API.
*
* This function retrieves the status of a terminal checkout using Square's API
- * and returns the result in JSON format. It uses the token provided in the GET
- * parameters for authorization and fetches the checkout ID from the WordPress
- * options.
+ * and returns the result in JSON format. Uses the stored merchant token server-side only.
*
* @return void
*/
@@ -432,39 +430,36 @@
if ( ! isset( $_GET['square_pay_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['square_pay_nonce'] ) ), 'square-pay-nonce' ) ) {
wp_die( esc_html( __( 'Cheatin’ huh?', 'woosquare-square' ) ) );
}
- if ( ! isset( $_GET['token'] ) ) {
- $token = sanitize_text_field( wp_unslash( $_GET['token'] ) );
- $headers = array(
- 'Accept' => 'application/json',
- 'Authorization' => 'Bearer ' . $token,
- 'Content-Type' => 'application/json',
- 'Cache-Control' => 'no-cache',
- );
-
- $checkout_id = get_option( 'terminal_checkout_id' );
- $url = 'https://connect.squareup' . get_transient( 'is_sandbox' ) . '.com/v2/terminals/checkouts/' . $checkout_id;
-
- $result = json_decode(
- wp_remote_retrieve_body(
- wp_remote_get(
- $url,
- array(
- 'method' => 'GET',
- 'headers' => $headers,
- 'httpversion' => '1.0',
- 'sslverify' => false,
- )
+ $token = get_option( 'woo_square_access_token' . get_transient( 'is_sandbox' ) );
+ $headers = array(
+ 'Accept' => 'application/json',
+ 'Authorization' => 'Bearer ' . $token,
+ 'Content-Type' => 'application/json',
+ 'Cache-Control' => 'no-cache',
+ );
+
+ $checkout_id = get_option( 'terminal_checkout_id' );
+ $url = 'https://connect.squareup' . get_transient( 'is_sandbox' ) . '.com/v2/terminals/checkouts/' . $checkout_id;
+
+ $result = json_decode(
+ wp_remote_retrieve_body(
+ wp_remote_get(
+ $url,
+ array(
+ 'method' => 'GET',
+ 'headers' => $headers,
+ 'httpversion' => '1.0',
+ 'sslverify' => false,
)
)
- );
- echo wp_json_encode(
- array(
- 'result' => 'Result_Status',
- 'result_info' => $result,
- )
- );
-
- }
+ )
+ );
+ echo wp_json_encode(
+ array(
+ 'result' => 'Result_Status',
+ 'result_info' => $result,
+ )
+ );
wp_die();
}
@@ -480,7 +475,7 @@
*/
public function my_ajax_get_pos_action_callback() {
- if ( ! isset( $_POST['nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'POSTerminal' ) ) {
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'POSTerminal' ) ) {
wp_die( esc_html__( 'Unauthorized Request', 'woosquare' ) );
}
$token = get_option( 'woo_square_access_token' . get_transient( 'is_sandbox' ) );
@@ -700,36 +695,28 @@
if ( ! isset( $_POST['cancel_terminal_checkout_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cancel_terminal_checkout_nonce'] ) ), 'cancel-terminal-checkout' ) ) {
wp_die( esc_html__( 'Unauthorized Request', 'woosquare' ) );
}
- if ( ! isset( $_POST['token'] ) ) {
- $token = sanitize_text_field( wp_unslash( $_POST['token'] ) );
- $idempotency_key = time();
- $checkout_id = get_option( 'terminal_checkout_id' );
- $url = 'https://connect.squareup.com/v2/terminals/checkouts/' . $checkout_id . '/cancel';
+ $token = get_option( 'woo_square_access_token' . get_transient( 'is_sandbox' ) );
+ $checkout_id = get_option( 'terminal_checkout_id' );
+ $url = 'https://connect.squareup' . get_transient( 'is_sandbox' ) . '.com/v2/terminals/checkouts/' . $checkout_id . '/cancel';
- $headers =
+ $headers = array(
+ 'Accept' => 'application/json',
+ 'Authorization' => 'Bearer ' . $token,
+ 'Content-Type' => 'application/json',
+ 'Square-Version' => '2021-03-17',
+ 'Cache-Control' => 'no-cache',
+ );
+
+ wp_remote_post(
+ $url,
array(
- 'Accept' => 'application/json',
- 'Authorization' => 'Bearer ' . $token,
- 'Content-Type' => 'application/json',
- 'Square-Version' => '2021-03-17',
- 'Cache-Control' => 'no-cache',
- );
-
- $checkout_cancel = json_decode(
- wp_remote_retrieve_body(
- wp_remote_post(
- $url,
- array(
- 'method' => 'POST',
- 'headers' => $headers,
- 'httpversion' => '1.0',
- 'sslverify' => false,
- 'body' => $checkout_cancel,
- )
- )
- )
- );
- }
+ 'method' => 'POST',
+ 'headers' => $headers,
+ 'httpversion' => '1.0',
+ 'sslverify' => false,
+ 'body' => '{}',
+ )
+ );
wp_die();
}
--- a/woosquare/admin/modules/square-payments/class-woosquarepos-gateway.php
+++ b/woosquare/admin/modules/square-payments/class-woosquarepos-gateway.php
@@ -291,7 +291,6 @@
$woocommerce_square_settings = get_option( 'woocommerce_square_settings' );
$currency_cod = get_option( 'woocommerce_currency' );
$country_code = $this->get_country_codes( $currency_cod );
- $access_token = get_option( 'woo_square_access_token' . get_transient( 'is_sandbox' ) );
$location_id = get_option( 'woo_square_location_id' . get_transient( 'is_sandbox' ) );
// need to add condition square payment enable so disable below script.
if ( get_transient( 'is_sandbox' ) ) {
@@ -328,7 +327,6 @@
'currency_code' => $currency_cod,
'country_code' => $country_code,
'nonce' => wp_create_nonce( 'squaretpay_params' ),
- 'access_token' => $access_token,
'location_id' => $location_id,
'sandbox' => get_transient( 'is_sandbox' ),
'square_pay_nonce' => wp_create_nonce( 'square-pay-nonce' ),
@@ -352,7 +350,6 @@
$woocommerce_square_settings = get_option( 'woocommerce_square_settings' );
$currency_cod = get_option( 'woocommerce_currency' );
$country_code = $this->get_country_codes( $currency_cod );
- $access_token = get_option( 'woo_square_access_token' . get_transient( 'is_sandbox' ) );
$location_id = get_option( 'woo_square_location_id' . get_transient( 'is_sandbox' ) );
// need to add condition square payment enable so disable below script.
@@ -363,7 +360,6 @@
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'POSTerminal' ),
- 'access_token' => $access_token,
'currency_code' => $currency_cod,
'currency_sym' => get_woocommerce_currency_symbol(),
'country_code' => $country_code,
--- a/woosquare/woocommerce-square-integration.php
+++ b/woosquare/woocommerce-square-integration.php
@@ -4,7 +4,7 @@
* Requires Plugins: woocommerce
* Plugin URI: https://wcshopsync.com/
* Description: WC Shop Sync purpose is to migrate & synchronize data (sales customers-invoices-products inventory) between Square system point of sale & WooCommerce plug-in.
- * Version: 4.7.3
+ * Version: 4.7.4
* Author: Wpexpertsio
* Author URI: https://wpexperts.io/
* License: GPLv2 or later