mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Adds nonce validation to refresh feature status request.
This commit is contained in:
parent
d2abeb5dbf
commit
81f606912f
2 changed files with 30 additions and 12 deletions
|
@ -354,9 +354,8 @@ document.addEventListener(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logic to handle the "Check available features" button.
|
||||||
(() => {
|
((props) => {
|
||||||
const props = PayPalCommerceGatewaySettings.ajax.refresh_feature_status;
|
|
||||||
const $btn = jQuery(props.button);
|
const $btn = jQuery(props.button);
|
||||||
|
|
||||||
$btn.click(async () => {
|
$btn.click(async () => {
|
||||||
|
@ -388,7 +387,7 @@ document.addEventListener(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})(PayPalCommerceGatewaySettings.ajax.refresh_feature_status);
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -78,19 +78,38 @@ class RefreshFeatureStatusEndpoint {
|
||||||
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
|
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
|
||||||
$seconds_missing = $last_request_time + self::TIMEOUT - $now;
|
$seconds_missing = $last_request_time + self::TIMEOUT - $now;
|
||||||
|
|
||||||
|
if ( ! $this->verify_nonce() ) {
|
||||||
|
wp_send_json_error(
|
||||||
|
array(
|
||||||
|
'message' => __( 'Expired request.', 'woocommerce-paypal-payments' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ( $seconds_missing > 0 ) {
|
if ( $seconds_missing > 0 ) {
|
||||||
$response = array(
|
wp_send_json_error(
|
||||||
|
array(
|
||||||
'message' => sprintf(
|
'message' => sprintf(
|
||||||
// translators: %1$s is the number of seconds remaining.
|
// translators: %1$s is the number of seconds remaining.
|
||||||
__( 'Wait %1$s seconds before trying again.', 'woocommerce-paypal-payments' ),
|
__( 'Wait %1$s seconds before trying again.', 'woocommerce-paypal-payments' ),
|
||||||
$seconds_missing
|
$seconds_missing
|
||||||
),
|
),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
wp_send_json_error( $response );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cache->set( self::CACHE_KEY, $now, self::TIMEOUT );
|
$this->cache->set( self::CACHE_KEY, $now, self::TIMEOUT );
|
||||||
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $this->settings );
|
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $this->settings );
|
||||||
wp_send_json_success();
|
wp_send_json_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the nonce.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function verify_nonce(): bool {
|
||||||
|
$json = json_decode( file_get_contents( 'php://input' ), true );
|
||||||
|
return wp_verify_nonce( $json['nonce'] ?? null, self::nonce() ) !== false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue