Skip to content

Add debugging to OAuth redirect handling for user issue #4354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/9.5.2
Choose a base branch
from

Conversation

daledupreez
Copy link
Contributor

@daledupreez daledupreez commented May 23, 2025

Changes proposed in this Pull Request:

This PR adds some raw debugging to try and uncover more details about the issue a merchant is seeing in this forum thread. As a result, the PR is based off the code in release/9.5.2, which is the version the user is using.

Based on the server logs I looked at (for api.woocommerce.com), the redirect back to the Stripe settings page in wp-admin is working as expected, so we suspect something is going awry when handling the redirect. Hence the logging here.

Note that the code is intentionally using error_log() as the user can't access the main settings page to toggle logging.

Testing instructions


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@daledupreez daledupreez changed the base branch from develop to release/9.5.2 May 23, 2025 10:48
@daledupreez daledupreez requested a review from Copilot May 23, 2025 10:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds temporary debugging logs to help diagnose an OAuth redirection issue a merchant is experiencing.

  • Wrapped conditions around user capability and nonce verification now include error log statements.
  • Debug logs are added to capture the outcome of the OAuth connection process.

@@ -107,6 +107,9 @@ public function maybe_handle_redirect() {
}

if ( ! current_user_can( 'manage_woocommerce' ) ) {
if ( isset( $_GET['wcs_stripe_code'], $_GET['wcs_stripe_state'] ) ) {
error_log( 'woocommerce_stripe: Current user does not have manage_woocommerce capability' );
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping the debugging log calls behind a debug flag so they are only executed in a controlled debugging environment. This would prevent unnecessary logging in production.

Suggested change
error_log( 'woocommerce_stripe: Current user does not have manage_woocommerce capability' );
if ( WC_STRIPE_DEBUG ) {
error_log( 'woocommerce_stripe: Current user does not have manage_woocommerce capability' );
}

Copilot uses AI. Check for mistakes.

@@ -115,6 +118,7 @@ public function maybe_handle_redirect() {
$nonce = isset( $_GET['_wpnonce'] ) ? wc_clean( wp_unslash( $_GET['_wpnonce'] ) ) : '';

if ( ! wp_verify_nonce( $nonce, 'wcs_stripe_connected' ) ) {
error_log( 'woocommerce_stripe: Invalid nonce received from Stripe server' );
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, consider conditionally logging the nonce validation failure to avoid cluttering production logs when debugging is not required.

Suggested change
error_log( 'woocommerce_stripe: Invalid nonce received from Stripe server' );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( 'woocommerce_stripe: Invalid nonce received from Stripe server' );
}

Copilot uses AI. Check for mistakes.

@@ -125,6 +129,11 @@ public function maybe_handle_redirect() {

$response = $this->connect_oauth( $state, $code, $type, $mode );

if ( is_wp_error( $response ) ) {
error_log( 'woocommerce_stripe: Error processing OAuth response: [' . $response->get_error_code() . '] ' . $response->get_error_message() );
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logging of OAuth error details (error code and message) could potentially expose sensitive information. Ensure that only non-sensitive details are logged or that these logs are removed once debugging is complete.

Suggested change
error_log( 'woocommerce_stripe: Error processing OAuth response: [' . $response->get_error_code() . '] ' . $response->get_error_message() );
error_log( 'woocommerce_stripe: An error occurred while processing the OAuth response. Please check the system logs for more details.' );

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant