Issues (197)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

compat/class-wc-stripe-pre-orders-compat.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Compatibility class for Pre-Orders.
8
 *
9
 */
10
class WC_Stripe_Pre_Orders_Compat extends WC_Stripe_Payment_Gateway {
11
	public $saved_cards;
12
13
	public function __construct() {
14
		$this->saved_cards = WC_Stripe_Helper::get_settings( 'stripe', 'saved_cards' );
15
	}
16
17
	/**
18
	 * Is $order_id a pre-order?
19
	 * @param  int  $order_id
20
	 * @return boolean
21
	 */
22
	public function is_pre_order( $order_id ) {
23
		return WC_Pre_Orders_Order::order_contains_pre_order( $order_id );
24
	}
25
26
	/**
27
	 * Remove order meta
28
	 * @param object $order
29
	 */
30
	public function remove_order_source_before_retry( $order ) {
31
		$order->delete_meta_data( '_stripe_source_id' );
32
		$order->delete_meta_data( '_stripe_card_id' );
33
		$order->save();
34
	}
35
36
	/**
37
	 * Process the pre-order when pay upon release is used.
38
	 * @param int $order_id
39
	 */
40
	public function process_pre_order( $order_id ) {
41
		try {
42
			$order = wc_get_order( $order_id );
43
44
			// This will throw exception if not valid.
45
			$this->validate_minimum_order_amount( $order );
46
47
			$prepared_source = $this->prepare_source( get_current_user_id(), true );
48
49
			// We need a source on file to continue.
50
			if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
51
				throw new WC_Stripe_Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
52
			}
53
54
			// Setup the response early to allow later modifications.
55
			$response = array(
56
				'result'   => 'success',
57
				'redirect' => $this->get_return_url( $order ),
58
			);
59
60
			$this->save_source_to_order( $order, $prepared_source );
61
62
			// Try setting up a payment intent.
63
			$intent_secret = $this->setup_intent( $order, $prepared_source );
64
			if ( ! empty( $intent_secret ) ) {
65
				$response['setup_intent_secret'] = $intent_secret;
66
				return $response;
67
			}
68
69
			// Remove cart.
70
			WC()->cart->empty_cart();
71
72
			// Is pre ordered!
73
			WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
74
75
			// Return thank you page redirect
76
			return $response;
77
		} catch ( WC_Stripe_Exception $e ) {
78
			wc_add_notice( $e->getLocalizedMessage(), 'error' );
79
			WC_Stripe_Logger::log( 'Pre Orders Error: ' . $e->getMessage() );
80
81
			return array(
82
				'result'   => 'success',
83
				'redirect' => $order->get_checkout_payment_url( true ),
84
			);
85
		}
86
	}
87
88
	/**
89
	 * Process a pre-order payment when the pre-order is released.
90
	 *
91
	 * @param WC_Order $order
92
	 * @param bool $retry
93
	 *
94
	 * @return void
95
	 */
96
	public function process_pre_order_release_payment( $order, $retry = true ) {
97
		try {
98
			$source   = $this->prepare_order_source( $order );
99
			$response = $this->create_and_confirm_intent_for_off_session( $order, $source );
100
101
			$is_authentication_required = $this->is_authentication_required_for_payment( $response );
102
103
			if ( ! empty( $response->error ) && ! $is_authentication_required ) {
104
				if ( ! $retry ) {
105
					throw new Exception( $response->error->message );
106
				}
107
				$this->remove_order_source_before_retry( $order );
108
				$this->process_pre_order_release_payment( $order, false );
109
			} else if ( $is_authentication_required ) {
110
				$charge = end( $response->error->payment_intent->charges->data );
111
				$id = $charge->id;
112
113
				$order->set_transaction_id( $id );
114
				$order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) );
115
				if ( is_callable( array( $order, 'save' ) ) ) {
116
					$order->save();
117
				}
118
119
				WC_Emails::instance();
120
121
				do_action( 'wc_gateway_stripe_process_payment_authentication_required', $order );
122
123
				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
124
			} else {
125
				// Successful
126
				$this->process_response( end( $response->charges->data ), $order );
127
			}
128
		} catch ( Exception $e ) {
129
			$error_message = is_callable( array( $e, 'getLocalizedMessage' ) ) ? $e->getLocalizedMessage() : $e->getMessage();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Exception as the method getLocalizedMessage() does only exist in the following sub-classes of Exception: WC_Stripe_Exception. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
130
			/* translators: error message */
131
			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $error_message );
132
133
			// Mark order as failed if not already set,
134
			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
135
			if ( ! $order->has_status( 'failed' ) ) {
136
				$order->update_status( 'failed', $order_note );
137
			} else {
138
				$order->add_order_note( $order_note );
139
			}
140
		}
141
	}
142
}
143