Skip to content

Commit a982699

Browse files
committed
fix: prevent wp_sanitize_redirect from stripping domain in payment URLs
- Remove wp_sanitize_redirect() from callback/complete/fail URLs - Use esc_url_raw() for URL sanitization (sufficient for API payloads) - Update token generation to use wc_get_account_endpoint_url() for absolute URLs wp_sanitize_redirect() strips domains not in WordPress allowed hosts list, causing completeUrl to become relative instead of absolute. MONEI API requires absolute URLs for callbacks. Since these URLs are internally generated (not user input) and already sanitized with esc_url_raw(), removing wp_sanitize_redirect() is safe and fixes payment failures. Affected files: - WCMoneiPaymentGatewayHosted.php - WCMoneiPaymentGatewayComponent.php - WCGatewayMoneiCC.php Fixes issue where completeUrl was sent as /order-received/123/ instead of https://example.com/order-received/123/
1 parent 62c8df2 commit a982699

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/Gateways/Abstracts/WCMoneiPaymentGatewayComponent.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,17 @@ public function create_payload( $order, $allowed_payment_method = null ) {
201201
$description = $this->shop_name . ' - #' . $order_id;
202202

203203
/** The URL to which a payment result should be sent asynchronously. */
204-
$callback_url = wp_sanitize_redirect( esc_url_raw( $this->notify_url ) );
204+
$callback_url = esc_url_raw( $this->notify_url );
205205
/** The URL the customer will be directed to if the payment failed. */
206206
$fail_url = esc_url_raw( $order->get_checkout_payment_url( false ) );
207207
/** The URL the customer will be directed to after transaction completed (successful or failed). */
208-
$complete_url = wp_sanitize_redirect(
209-
esc_url_raw(
210-
add_query_arg(
211-
array(
212-
'utm_nooverride' => '1',
213-
'orderId' => $order_id,
214-
),
215-
$this->get_return_url( $order )
216-
)
208+
$complete_url = esc_url_raw(
209+
add_query_arg(
210+
array(
211+
'utm_nooverride' => '1',
212+
'orderId' => $order_id,
213+
),
214+
$this->get_return_url( $order )
217215
)
218216
);
219217

src/Gateways/Abstracts/WCMoneiPaymentGatewayHosted.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function process_payment( $order_id, $allowed_payment_method = null ) {
3737
$description = $this->shop_name . ' - #' . $order_id;
3838

3939
/** The URL to which a payment result should be sent asynchronously. */
40-
$callback_url = wp_sanitize_redirect( esc_url_raw( $this->notify_url ) );
40+
$callback_url = esc_url_raw( $this->notify_url );
4141
/** The URL the customer will be directed to if the payment failed. */
4242
$fail_url = esc_url_raw( $order->get_checkout_payment_url( false ) );
4343
/** The URL the customer will be directed to after transaction completed (successful or failed). */
44-
$complete_url = wp_sanitize_redirect( esc_url_raw( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) ) );
44+
$complete_url = esc_url_raw( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) );
4545

4646
/** Create Payment Payload */
4747
$payload = array(

src/Gateways/PaymentMethods/WCGatewayMoneiCC.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ protected function create_zero_eur_payload() {
294294
'currency' => get_woocommerce_currency(),
295295
'orderId' => $current_user_id . 'generatetoken' . wp_rand( 0, 1000000 ),
296296
'description' => "User $current_user_id creating empty transaction to generate token",
297-
'callbackUrl' => wp_sanitize_redirect( esc_url_raw( $this->notify_url ) ),
298-
'completeUrl' => wc_get_endpoint_url( 'payment-methods' ),
299-
'cancelUrl' => wc_get_endpoint_url( 'payment-methods' ),
300-
'failUrl' => wc_get_endpoint_url( 'payment-methods' ),
297+
'callbackUrl' => esc_url_raw( $this->notify_url ),
298+
'completeUrl' => esc_url_raw( wc_get_account_endpoint_url( 'payment-methods' ) ),
299+
'cancelUrl' => esc_url_raw( wc_get_account_endpoint_url( 'payment-methods' ) ),
300+
'failUrl' => esc_url_raw( wc_get_account_endpoint_url( 'payment-methods' ) ),
301301
'transactionType' => self::VERIFY_TRANSACTION_TYPE,
302302
'sessionDetails' => array(
303303
'ip' => WC_Geolocation::get_ip_address(),

0 commit comments

Comments
 (0)