Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wp-express-checkout/includes/class-coupons.php
+++ b/wp-express-checkout/includes/class-coupons.php
@@ -566,8 +566,8 @@
// Redeem coupon count if needed.
if ( $coupon && $coupon['valid'] ) {
- $curr_redeem_cnt = get_post_meta( $coupon['id'], 'wpec_coupon_red_count', true );
- $curr_redeem_cnt++;
+ // The count is an empty string for a coupon that hasn't been used yet (incrementing an empty string is deprecated in PHP 8.3+).
+ $curr_redeem_cnt = intval( get_post_meta( $coupon['id'], 'wpec_coupon_red_count', true ) ) + 1;
update_post_meta( $coupon['id'], 'wpec_coupon_red_count', $curr_redeem_cnt );
}
}
--- a/wp-express-checkout/includes/class-payment-processor-manual.php
+++ b/wp-express-checkout/includes/class-payment-processor-manual.php
@@ -104,6 +104,9 @@
$this->send_error( $exc->getMessage(), $exc->getCode() );
}
+ // The name sent by the browser is only used to find the product's price data (the transient); the order gets the product's name.
+ $item_name = $product->get_item_name();
+
$order->set_payment_gateway( 'manual_checkout' );
/* translators: Order title: {Quantity} {Item name} - {Status} */
$order->set_description( sprintf( __( '%1$d %2$s - %3$s', 'wp-express-checkout' ), $quantity, $item_name, $this->transaction_status ) );
--- a/wp-express-checkout/includes/class-payment-processor-stripe.php
+++ b/wp-express-checkout/includes/class-payment-processor-stripe.php
@@ -333,10 +333,18 @@
public static function check_if_checkout_session_processed( $session_id ) {
+ // create_order() saves the checkout session ID as the order's resource ID (the capture ID is the charge ID).
+ // The capture ID is checked too, in case an order was saved with the session ID there.
$query = new WP_Query( array(
'post_type' => 'ppdgorder',
+ 'post_status' => 'any',
'posts_per_page' => 1, // Only need to know if it exists
'meta_query' => [
+ 'relation' => 'OR',
+ [
+ 'key' => 'wpec_order_resource_id',
+ 'value' => sanitize_text_field( $session_id ),
+ ],
[
'key' => 'wpec_order_capture_id',
'value' => sanitize_text_field( $session_id ),
--- a/wp-express-checkout/includes/class-payment-processor.php
+++ b/wp-express-checkout/includes/class-payment-processor.php
@@ -111,6 +111,9 @@
$this->send_error( $exc->getMessage(), $exc->getCode() );
}
+ // The name sent by the browser is only used to find the product's price data (the transient); the order gets the product's name.
+ $item_name = $product->get_item_name();
+
$order->set_payment_gateway( 'paypal' );
/* translators: Order title: {Quantity} {Item name} - {Status} */
$order->set_description( sprintf( __( '%1$d %2$s - %3$s', 'wp-express-checkout' ), $quantity, $item_name, $this->get_transaction_status( $payment ) ) );
@@ -285,6 +288,9 @@
$this->send_error( $exc->getMessage(), $exc->getCode() );
}
+ // The name sent by the browser is only used to find the product's price data (the transient); the order gets the product's name.
+ $item_name = $product->get_item_name();
+
$order->set_payment_gateway( 'paypal' );
/* translators: Order title: {Quantity} {Item name} - {Status} */
$order->set_description( sprintf( __( '%1$d %2$s - %3$s', 'wp-express-checkout' ), $quantity, $item_name, $this->get_transaction_status( $payment ) ) );
@@ -421,6 +427,8 @@
*/
protected function get_payment_data() {
$payment = isset( $_POST['wp_ppdg_payment'] ) ? stripslashes_deep( $_POST['wp_ppdg_payment'] ) : array();
+ // The buyer details (name, email, phone, address) come from the browser: keep text only.
+ $payment = is_array( $payment ) ? map_deep( $payment, 'sanitize_text_field' ) : array();
return $payment;
}
--- a/wp-express-checkout/includes/class-stripe-button-ajax-handler.php
+++ b/wp-express-checkout/includes/class-stripe-button-ajax-handler.php
@@ -72,7 +72,8 @@
'price_data' => array(
'currency' => $currency,
'product_data' => array(
- 'name' => $product_name,
+ // The product's name (the name sent by the browser is only used to find the product's price data).
+ 'name' => $product->get_item_name(),
'metadata' => array(
'wpec_product_id' => $product_id,
'wpec_item_key' => 'main',
--- a/wp-express-checkout/public/includes/class-order-tags-html.php
+++ b/wp-express-checkout/public/includes/class-order-tags-html.php
@@ -5,6 +5,9 @@
/**
* Order tags generator with HTML output.
*
+ * The values come from the order (much of it entered by the buyer), so they are escaped for HTML here.
+ * The plain text generator (Order_Tags_Plain, used for the emails) returns them unescaped.
+ *
* @since 2.1.0
*/
class Order_Tags_Html {
@@ -24,13 +27,36 @@
}
/**
+ * Prepares a text value for output: escaped for HTML.
+ *
+ * @param mixed $value The value.
+ *
+ * @return string
+ */
+ protected function output( $value ) {
+ return esc_html( (string) $value );
+ }
+
+ /**
+ * Prepares the output of a custom order tag (added with the 'wpec_render_custom_order_tag' filter):
+ * HTML is allowed, but not scripts or event handler attributes.
+ *
+ * @param mixed $value The value.
+ *
+ * @return mixed
+ */
+ protected function output_custom_tag( $value ) {
+ return is_scalar( $value ) ? wp_kses_post( (string) $value ) : $value;
+ }
+
+ /**
* Order author first name.
*
* @return string
*/
public function first_name() {
$payer_details = $this->order->get_data( 'payer' );
- return $payer_details['name']['given_name'];
+ return $this->output( isset( $payer_details['name']['given_name'] ) ? $payer_details['name']['given_name'] : '' );
}
/**
@@ -40,7 +66,7 @@
*/
public function last_name() {
$payer_details = $this->order->get_data( 'payer' );
- return $payer_details['name']['surname'];
+ return $this->output( isset( $payer_details['name']['surname'] ) ? $payer_details['name']['surname'] : '' );
}
/**
@@ -63,7 +89,7 @@
* @return string
*/
public function payer_email() {
- return $this->order->get_info( 'email' );
+ return $this->output( $this->order->get_info( 'email' ) );
}
/**
@@ -72,7 +98,7 @@
* @return string
*/
public function payer_phone() {
- return $this->order->get_phone();
+ return $this->output( $this->order->get_phone() );
}
/**
@@ -81,7 +107,7 @@
* @return string
*/
public function transaction_id() {
- return $this->order->get_capture_id();
+ return $this->output( $this->order->get_capture_id() );
}
/**
@@ -90,7 +116,7 @@
* @return float
*/
public function purchase_amt() {
- return $this->order->get_total();
+ return $this->output( $this->order->get_total() );
}
/**
@@ -99,15 +125,15 @@
* @return string
*/
public function purchase_date() {
- return get_post_time( 'F j, Y, g:i a', false, $this->order->get_id() );
+ return $this->output( get_post_time( 'F j, Y, g:i a', false, $this->order->get_id() ) );
}
public function quantity_ordered() {
- return $this->order->get_quantity_ordered();
+ return $this->output( $this->order->get_quantity_ordered() );
}
public function selected_variations() {
- return $this->order->get_selected_variations_string();
+ return $this->output( $this->order->get_selected_variations_string() );
}
/**
@@ -116,7 +142,7 @@
* @return string
*/
public function currency_code() {
- return $this->order->get_currency();
+ return $this->output( $this->order->get_currency() );
}
/**
@@ -126,7 +152,7 @@
*/
public function coupon_code() {
$coupon_item = $this->order->get_item( 'coupon' );
- return ! empty( $coupon_item['meta']['code'] ) ? $coupon_item['meta']['code'] : '0';
+ return $this->output( ! empty( $coupon_item['meta']['code'] ) ? $coupon_item['meta']['code'] : '0' );
}
/**
@@ -135,7 +161,7 @@
* @return string
*/
public function address() {
- return $this->order->get_shipping_address();
+ return $this->output( $this->order->get_shipping_address() );
}
/**
@@ -144,7 +170,7 @@
* @return int
*/
public function order_id() {
- return $this->order->get_id();
+ return $this->output( $this->order->get_id() );
}
/**
@@ -188,7 +214,7 @@
foreach ( $downloads as $name => $download_url ) {
$count = ! empty( $counter[ $name ] ) ? $counter[ $name ] : 0;
$text = ! empty( $args['anchor_text'] ) ? $args['anchor_text'] : $download_url;
- $content .= sprintf( $link_tpl, $name, $download_url, $args['target'], $text, $count, $limit ? $limit : '∞' );
+ $content .= sprintf( $link_tpl, esc_html( $name ), esc_url( $download_url ), esc_attr( $args['target'] ), esc_html( $text ), (int) $count, $limit ? $limit : '∞' );
}
return $content;
@@ -201,7 +227,7 @@
*/
public function product_id() {
$product_item = $this->order->get_item( 'ppec-products' );
- return ! empty( $product_item['post_id'] ) ? $product_item['post_id'] : 0;
+ return $this->output( ! empty( $product_item['post_id'] ) ? $product_item['post_id'] : 0 );
}
/**
@@ -210,8 +236,9 @@
* @return string
*/
public function product_name() {
- $product = get_post( $this->product_id() );
- return $product ? $product->post_title : '';
+ $product_item = $this->order->get_item( 'ppec-products' );
+ $product = ! empty( $product_item['post_id'] ) ? get_post( $product_item['post_id'] ) : null;
+ return $this->output( $product ? $product->post_title : '' );
}
/**
@@ -222,7 +249,7 @@
*/
public function __call( $name, $arguments ) {
$arguments['renderer'] = $this;
- return apply_filters( 'wpec_render_custom_order_tag', null, $name, $arguments );
+ return $this->output_custom_tag( apply_filters( 'wpec_render_custom_order_tag', null, $name, $arguments ) );
}
}
--- a/wp-express-checkout/public/includes/class-order-tags-plain.php
+++ b/wp-express-checkout/public/includes/class-order-tags-plain.php
@@ -10,6 +10,28 @@
class Order_Tags_Plain extends Order_Tags_Html {
/**
+ * Plain text: the values are not escaped (the emails are plain text).
+ *
+ * @param mixed $value The value.
+ *
+ * @return mixed
+ */
+ protected function output( $value ) {
+ return $value;
+ }
+
+ /**
+ * Plain text: a custom order tag's value is not changed.
+ *
+ * @param mixed $value The value.
+ *
+ * @return mixed
+ */
+ protected function output_custom_tag( $value ) {
+ return $value;
+ }
+
+ /**
* Generates Order Summary Table.
*
* @return string
--- a/wp-express-checkout/wp-express-checkout.php
+++ b/wp-express-checkout/wp-express-checkout.php
@@ -2,7 +2,7 @@
/**
* Plugin Name: WP Express Checkout
* Description: Allows you to accept fast and secure payments for products and services via a payment popup window, supporting both the new PayPal and Stripe Checkout options.
- * Version: 2.5.5
+ * Version: 2.5.6
* Author: Tips and Tricks HQ, mra13
* Author URI: https://www.tipsandtricks-hq.com/
* Plugin URI: https://wp-express-checkout.com/
@@ -17,7 +17,7 @@
}
//Define constants
-define( 'WPEC_PLUGIN_VER', '2.5.5' );
+define( 'WPEC_PLUGIN_VER', '2.5.6' );
define( 'WPEC_PLUGIN_URL', plugins_url( '', __FILE__ ) );
define( 'WPEC_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'WPEC_PLUGIN_FILE', __FILE__ );