Issues (1182)

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.

gateways/cheque/class-wc-gateway-cheque.php (5 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; // Exit if accessed directly
5
}
6
7
/**
8
 * Cheque Payment Gateway.
9
 *
10
 * Provides a Cheque Payment Gateway, mainly for testing purposes.
11
 *
12
 * @class 		WC_Gateway_Cheque
13
 * @extends		WC_Payment_Gateway
14
 * @version		2.1.0
15
 * @package		WooCommerce/Classes/Payment
16
 * @author 		WooThemes
17
 */
18
class WC_Gateway_Cheque extends WC_Payment_Gateway {
19
20
    /**
21
     * Constructor for the gateway.
22
     */
23
	public function __construct() {
24
		$this->id                 = 'cheque';
25
		$this->icon               = apply_filters( 'woocommerce_cheque_icon', '' );
26
		$this->has_fields         = false;
27
		$this->method_title       = _x( 'Check Payments', 'Check payment method', 'woocommerce' );
28
		$this->method_description = __( 'Allows check payments. Why would you take checks in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce' );
29
30
		// Load the settings.
31
		$this->init_form_fields();
32
		$this->init_settings();
33
34
		// Define user set variables
35
		$this->title        = $this->get_option( 'title' );
36
		$this->description  = $this->get_option( 'description' );
37
		$this->instructions = $this->get_option( 'instructions', $this->description );
38
39
		// Actions
40
		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
41
    	add_action( 'woocommerce_thankyou_cheque', array( $this, 'thankyou_page' ) );
42
43
    	// Customer Emails
44
    	add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
45
    }
46
47
    /**
48
     * Initialise Gateway Settings Form Fields.
49
     */
50 View Code Duplication
    public function init_form_fields() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
52
    	$this->form_fields = array(
53
			'enabled' => array(
54
				'title'   => __( 'Enable/Disable', 'woocommerce' ),
55
				'type'    => 'checkbox',
56
				'label'   => __( 'Enable Check Payments', 'woocommerce' ),
57
				'default' => 'yes'
58
			),
59
			'title' => array(
60
				'title'       => __( 'Title', 'woocommerce' ),
61
				'type'        => 'text',
62
				'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
63
				'default'     => _x( 'Check Payments', 'Check payment method', 'woocommerce' ),
64
				'desc_tip'    => true,
65
			),
66
			'description' => array(
67
				'title'       => __( 'Description', 'woocommerce' ),
68
				'type'        => 'textarea',
69
				'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
70
				'default'     => __( 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woocommerce' ),
71
				'desc_tip'    => true,
72
			),
73
			'instructions' => array(
74
				'title'       => __( 'Instructions', 'woocommerce' ),
75
				'type'        => 'textarea',
76
				'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
77
				'default'     => '',
78
				'desc_tip'    => true,
79
			),
80
		);
81
    }
82
83
    /**
84
     * Output for the order received page.
85
     */
86
	public function thankyou_page() {
87
		if ( $this->instructions )
88
        	echo wpautop( wptexturize( $this->instructions ) );
89
	}
90
91
    /**
92
     * Add content to the WC emails.
93
     *
94
     * @access public
95
     * @param WC_Order $order
96
     * @param bool $sent_to_admin
97
     * @param bool $plain_text
98
     */
99
	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
0 ignored issues
show
The parameter $plain_text 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...
100 View Code Duplication
        if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->payment_method && $order->has_status( 'on-hold' ) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
			echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
102
		}
103
	}
104
105
    /**
106
     * Process the payment and return the result.
107
     *
108
     * @param int $order_id
109
     * @return array
110
     */
111 View Code Duplication
	public function process_payment( $order_id ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
113
		$order = wc_get_order( $order_id );
114
115
		// Mark as on-hold (we're awaiting the cheque)
116
		$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
117
118
		// Reduce stock levels
119
		$order->reduce_order_stock();
120
121
		// Remove cart
122
		WC()->cart->empty_cart();
123
124
		// Return thankyou redirect
125
		return array(
126
			'result' 	=> 'success',
127
			'redirect'	=> $this->get_return_url( $order )
0 ignored issues
show
$order is of type false|object, but the function expects a object<WC_Order>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
		);
129
	}
130
}
131