Skip to content

Commit baef416

Browse files
authored
Add the masked stored state (transient value) when OAuth Connect validation fails (#4806)
* Add the masked stored state (transient value) when validation fails
1 parent 20a20a6 commit baef416

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Fix - Disable express checkout when Amazon Pay is disabled and the only method
1818
* Fix - Don't allow WP-Cron jobs to detach payment methods on staging sites
1919
* Update - Add minimum transaction amounts for BRL, INR, NZD, THB, CZK, HUF, AED, MYR, PLN, RON
20+
* Dev - Add additional context data to the OAuth connect flow verbose debug logging mode
2021

2122
= 10.1.0 - 2025-11-11 =
2223
* Dev - Remove unused `shouldShowPaymentRequestButton` parameter and calculations from backend

includes/connect/class-wc-stripe-connect.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public function connect_oauth( $state, $code, $type = 'connect', $mode = 'live'
9595
// The state parameter is used to protect against CSRF.
9696
// It's a unique, randomly generated, opaque, and non-guessable string that is sent when starting the
9797
// authentication request and validated when processing the response.
98-
if ( get_transient( 'wcs_stripe_connect_state_' . $mode ) !== $state ) {
98+
$stored_state = get_transient( 'wcs_stripe_connect_state_' . $mode );
99+
if ( $stored_state !== $state ) {
99100
if ( WC_Stripe_Helper::is_verbose_debug_mode_enabled() ) {
100101
WC_Stripe_Logger::error(
101102
'OAuth: Invalid state received from the WCC server',
@@ -105,6 +106,7 @@ public function connect_oauth( $state, $code, $type = 'connect', $mode = 'live'
105106
'connect_type' => $type,
106107
'state' => self::redact_string( $state ),
107108
'code' => self::redact_string( $code ),
109+
'stored_state' => false === $stored_state ? 'false' : self::redact_string( $stored_state ),
108110
]
109111
);
110112
}
@@ -196,16 +198,22 @@ public function maybe_handle_redirect() {
196198
}
197199

198200
if ( $is_verbose_debug_mode_enabled ) {
199-
WC_Stripe_Logger::debug(
200-
'OAuth: Account connected successfully, reloading the page to clear URL parameters',
201-
[
202-
'current_stripe_api_key' => WC_Stripe_API::get_masked_secret_key(),
203-
'connect_mode' => $mode,
204-
'connect_type' => $type,
205-
'connect_response' => self::redact_sensitive_data( $response ),
206-
'redirect_url' => self::redact_sensitive_data( $redirect_url ),
207-
]
208-
);
201+
$log_data = [
202+
'current_stripe_api_key' => WC_Stripe_API::get_masked_secret_key(),
203+
'connect_mode' => $mode,
204+
'connect_type' => $type,
205+
'state' => self::redact_string( $state ),
206+
'code' => self::redact_string( $code ),
207+
'nonce' => self::redact_string( $nonce ),
208+
'connect_response' => self::redact_sensitive_data( $response ),
209+
'redirect_url' => self::redact_sensitive_data( $redirect_url ),
210+
];
211+
212+
if ( ! is_wp_error( $response ) ) {
213+
WC_Stripe_Logger::debug( 'OAuth: Account connected successfully', $log_data );
214+
} else {
215+
WC_Stripe_Logger::error( 'OAuth: Account connection failed', $log_data );
216+
}
209217
}
210218

211219
wp_safe_redirect( esc_url_raw( $redirect_url ) );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
127127
* Fix - Disable express checkout when Amazon Pay is disabled and the only method
128128
* Fix - Don't allow WP-Cron jobs to detach payment methods on staging sites
129129
* Update - Add minimum transaction amounts for BRL, INR, NZD, THB, CZK, HUF, AED, MYR, PLN, RON
130+
* Dev - Add additional context data to the OAuth connect flow verbose debug logging mode
130131

131132
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)