Skip to content

Commit 4a12172

Browse files
committed
fix nonce check
1 parent 4b2351a commit 4a12172

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

includes/Form_Handler.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function init() {
3535
public function pay_action() {
3636
global $wp;
3737

38-
if ( woocommerce_pos_request() && isset( $_POST['woocommerce_pay'], $_GET['key'], $_GET['token'] ) ) {
38+
if ( woocommerce_pos_request() && isset( $_POST['woocommerce_pay'], $_GET['key'] ) ) {
3939
$order_id = absint( $wp->query_vars['order-pay'] );
4040
$order = wc_get_order( $order_id );
4141

@@ -58,8 +58,20 @@ public function pay_action() {
5858
);
5959
}
6060

61+
// Check for 'wcpos_jwt' and fall back to 'token' if not present.
62+
// remove 'token' when wcpos_jwt is fully implemented.
63+
$token_key = isset( $_GET['wcpos_jwt'] ) ? 'wcpos_jwt' : ( isset( $_GET['token'] ) ? 'token' : null );
64+
65+
if ( $token_key === null || ! isset( $_GET[ $token_key ] ) ) {
66+
wp_die(
67+
esc_html__( 'Token not provided.', 'woocommerce-pos' ),
68+
esc_html__( 'Error', 'woocommerce-pos' ),
69+
array( 'response' => 403 )
70+
);
71+
}
72+
6173
// Verify the cashier is authorized to access the order.
62-
$provided_token = sanitize_text_field( wp_unslash( $_GET['token'] ) );
74+
$provided_token = sanitize_text_field( wp_unslash( $_GET[ $token_key ] ) );
6375
$auth = AuthService::instance();
6476
$user = $auth->validate_token( $provided_token );
6577
if ( is_wp_error( $user ) ) {

includes/Templates/Payment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function get_template(): void {
153153
* @TODO - is this the best way to do this?
154154
*/
155155
wp_set_current_user( $order->get_customer_id() );
156+
add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
156157

157158
// create nonce for customer
158159
// $nonce_field = '<input type="hidden" id="woocommerce-pay-nonce" name="woocommerce-pay-nonce" value="' . $this->create_customer_nonce() . '" />';
@@ -249,6 +250,17 @@ private function check_troubleshooting_form_submission(): void {
249250
}
250251
}
251252

253+
/**
254+
* Fix: when checking out as Guest on the desktop application, WordPress gets a $uid from the
255+
* session, eg: 't_8b04f8283e7edc5aeee2867c89dd06'. This causes the nonce check to fail.
256+
*/
257+
public function nonce_user_logged_out( $uid, $action ) {
258+
if ( $action === 'woocommerce-pay' ) {
259+
return 0;
260+
}
261+
return $uid;
262+
}
263+
252264
/**
253265
* Custom version of wp_create_nonce that uses the customer ID.
254266
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wcpos/woocommerce-pos",
3-
"version": "1.4.15",
3+
"version": "1.4.16",
44
"description": "A simple front-end for taking WooCommerce orders at the Point of Sale.",
55
"main": "index.js",
66
"workspaces": {

readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: kilbot
33
Tags: ecommerce, point-of-sale, pos, inventory, woocommerce
44
Requires at least: 5.6
55
Tested up to: 6.5
6-
Stable tag: 1.4.15
6+
Stable tag: 1.4.16
77
License: GPL-3.0
88
License URI: http://www.gnu.org/licenses/gpl-3.0.html
99

@@ -79,7 +79,7 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co
7979
== Changelog ==
8080

8181
= 1.4.16 - 2024/03/22 =
82-
* Fix: namespace checkout token, this may help some situations where checkout is not completing
82+
* Fix: nonce check failing for Guest orders when checking out with the desktop application
8383

8484
= 1.4.15 - 2024/03/20 =
8585
* Fix: another potential error introduced to Pro updater in previous version 🤦‍♂️

woocommerce-pos.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
* Plugin Name: WooCommerce POS
44
* Plugin URI: https://wordpress.org/plugins/woocommerce-pos/
55
* Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
6-
* Version: 1.4.15
6+
* Version: 1.4.16
77
* Author: kilbot
88
* Author URI: http://wcpos.com
99
* Text Domain: woocommerce-pos
1010
* License: GPL-3.0+
1111
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
1212
* Domain Path: /languages
1313
* Requires at least: 5.6
14+
* Tested up to: 6.5
1415
* Requires PHP: 7.4
1516
* Requires Plugins: woocommerce
16-
* Tested up to: 6.5
17-
* WC tested up to: 8.6
17+
* WC tested up to: 8.7
1818
* WC requires at least: 5.3
1919
*
2020
* @author Paul Kilmurray <[email protected]>
@@ -26,7 +26,7 @@
2626
namespace WCPOS\WooCommercePOS;
2727

2828
// Define plugin constants.
29-
const VERSION = '1.4.15';
29+
const VERSION = '1.4.16';
3030
const PLUGIN_NAME = 'woocommerce-pos';
3131
const SHORT_NAME = 'wcpos';
3232
\define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'

0 commit comments

Comments
 (0)