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.

includes/connect/class-wc-stripe-connect.php (3 issues)

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
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
if ( ! class_exists( 'WC_Stripe_Connect' ) ) {
8
	/**
9
	 * Stripe Connect class.
10
	 */
11
	class WC_Stripe_Connect {
12
13
		const SETTINGS_OPTION = 'woocommerce_stripe_settings';
14
15
		/**
16
		 * Stripe connect api.
17
		 *
18
		 * @var object $api
19
		 */
20
		private $api;
21
22
		/**
23
		 * Constructor.
24
		 *
25
		 * @param WC_Stripe_Connect_API $api stripe connect api.
26
		 */
27
		public function __construct( WC_Stripe_Connect_API $api ) {
28
			$this->api = $api;
29
30
			add_action( 'admin_init', array( $this, 'maybe_handle_redirect' ) );
31
		}
32
33
		/**
34
		 * Gets the OAuth URL for Stripe onboarding flow
35
		 *
36
		 * @param  string $return_url url to return to after oauth flow.
37
		 *
38
		 * @return string|WP_Error
39
		 */
40
		public function get_oauth_url( $return_url = '' ) {
41
42
			if ( empty( $return_url ) ) {
43
				$return_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' );
44
			}
45
46
			if ( substr( $return_url, 0, 8 ) !== 'https://' ) {
47
				return new WP_Error( 'invalid_url_protocol', __( 'Your site must be served over HTTPS in order to connect your Stripe account automatically.', 'woocommerce-gateway-stripe' ) );
48
			}
49
50
			$result = $this->api->get_stripe_oauth_init( $return_url );
51
52
			if ( is_wp_error( $result ) ) {
53
				return $result;
54
			}
55
56
			return $result->oauthUrl; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
57
		}
58
59
		/**
60
		 * Initiate OAuth connection request to Connect Server
61
		 *
62
		 * @param  bool $state Stripe onboarding state.
63
		 * @param  int  $code  OAuth code.
64
		 *
65
		 * @return string|WP_Error
66
		 */
67
		public function connect_oauth( $state, $code ) {
0 ignored issues
show
The parameter $state is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
69
			$response = $this->api->get_stripe_oauth_keys( $code );
70
71
			if ( is_wp_error( $response ) ) {
72
				return $response;
73
			}
74
75
			return $this->save_stripe_keys( $response );
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->save_stripe_keys($response); of type WP_Error|array adds the type array to the return on line 75 which is incompatible with the return type documented by WC_Stripe_Connect::connect_oauth of type string|WP_Error.
Loading history...
76
		}
77
78
		/**
79
		 * Handle redirect back from oauth-init or credentials reset
80
		 */
81
		public function maybe_handle_redirect() {
82
			if ( ! is_admin() ) {
83
				return;
84
			}
85
86
			// redirect from oauth-init
87
			if ( isset( $_GET['wcs_stripe_code'], $_GET['wcs_stripe_state'] ) ) {
88
89
				$response = $this->connect_oauth( $_GET['wcs_stripe_state'], $_GET['wcs_stripe_code'] );
0 ignored issues
show
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
90
				wp_safe_redirect( remove_query_arg( array( 'wcs_stripe_state', 'wcs_stripe_code' ) ) );
91
				exit;
92
93
			// redirect from credentials reset
94
			} elseif ( isset( $_GET['reset_stripe_api_credentials'], $_GET['_wpnonce'] ) ) {
95
96
				if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'reset_stripe_api_credentials' ) ) {
97
					die( __( 'You are not authorized to clear Stripe account keys.', 'woocommerce-gateway-stripe' ) );
98
				}
99
100
				$this->clear_stripe_keys();
101
				wp_safe_redirect(
102
					remove_query_arg(
103
						array(
104
							'_wpnonce',
105
							'reset_stripe_api_credentials',
106
						)
107
					)
108
				);
109
				exit;
110
			}
111
112
		}
113
114
		/**
115
		 * Saves stripe keys after OAuth response
116
		 *
117
		 * @param  array $result OAuth response result.
118
		 *
119
		 * @return array|WP_Error
120
		 */
121
		private function save_stripe_keys( $result ) {
122
123
			if ( ! isset( $result->publishableKey, $result->secretKey ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
124
				return new WP_Error( 'Invalid credentials received from WooCommerce Connect server' );
125
			}
126
127
			$is_test                                = false !== strpos( $result->publishableKey, '_test_' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
128
			$prefix                                 = $is_test ? 'test_' : '';
129
			$default_options                        = $this->get_default_stripe_config();
130
			$options                                = array_merge( $default_options, get_option( self::SETTINGS_OPTION, array() ) );
131
			$options['enabled']                     = 'yes';
132
			$options['testmode']                    = $is_test ? 'yes' : 'no';
133
			$options[ $prefix . 'publishable_key' ] = $result->publishableKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
134
			$options[ $prefix . 'secret_key' ]      = $result->secretKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
135
136
			// While we are at it, let's also clear the account_id and
137
			// test_account_id if present.
138
			unset( $options['account_id'] );
139
			unset( $options['test_account_id'] );
140
141
			update_option( self::SETTINGS_OPTION, $options );
142
143
			return $result;
144
		}
145
146
		/**
147
		 * Clears keys for test or production (whichever is presently enabled).
148
		 */
149
		private function clear_stripe_keys() {
150
151
			$options = get_option( self::SETTINGS_OPTION, array() );
152
153
			if ( 'yes' === $options['testmode'] ) {
154
				$options['test_publishable_key'] = '';
155
				$options['test_secret_key']      = '';
156
				// clear test_account_id if present
157
				unset( $options['test_account_id'] );
158
			} else {
159
				$options['publishable_key'] = '';
160
				$options['secret_key']      = '';
161
				// clear account_id if present
162
				unset( $options['account_id'] );
163
			}
164
165
			update_option( self::SETTINGS_OPTION, $options );
166
167
		}
168
169
		/**
170
		 * Gets default Stripe settings
171
		 */
172
		private function get_default_stripe_config() {
173
174
			$result = array();
175
			$gateway = new WC_Gateway_Stripe();
176
			foreach ( $gateway->form_fields as $key => $value ) {
177
				if ( isset( $value['default'] ) ) {
178
					$result[ $key ] = $value['default'];
179
				}
180
			}
181
182
			return $result;
183
		}
184
185
		public function is_connected() {
186
187
			$options = get_option( self::SETTINGS_OPTION, array() );
188
189
			if ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) {
190
				return isset( $options['test_publishable_key'], $options['test_secret_key'] ) && trim( $options['test_publishable_key'] ) && trim( $options['test_secret_key'] );
191
			} else {
192
				return isset( $options['publishable_key'], $options['secret_key'] ) && trim( $options['publishable_key'] ) && trim( $options['secret_key'] );
193
			}
194
		}
195
	}
196
}
197