Issues (850)

Security Analysis    4 potential vulnerabilities

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection (1)
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection (2)
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  Cross-Site Scripting (1)
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.
  Header Injection
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.

class-getpaid-payment-form-submission-items.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Processes items for a payment form submission.
4
 *
5
 */
6
7
defined( 'ABSPATH' ) || exit;
8
9
/**
10
 * Payment form submission itemss class
11
 *
12
 */
13
class GetPaid_Payment_Form_Submission_Items {
14
15
	/**
16
	 * Submission items.
17
	 * @var GetPaid_Form_Item[]
18
	 */
19
	public $items = array();
20
21
    /**
22
	 * Class constructor
23
	 *
24
	 * @param GetPaid_Payment_Form_Submission $submission
25
	 */
26
	public function __construct( $submission ) {
27
28
		$data         = $submission->get_data();
29
		$payment_form = $submission->get_payment_form();
30
		$invoice      = $submission->get_invoice();
31
		$force_prices = array();
32
33
		// Prepare the selected items.
34
		$selected_items = array();
35
		if ( ! empty( $data['getpaid-items'] ) ) {
36
			$selected_items = wpinv_clean( $data['getpaid-items'] );
37
38
			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
39
				foreach ( $invoice->get_items() as $invoice_item ) {
40
					if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) {
41
						$selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
42
						$selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
43
44
						$force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
45
					}
46
				}
47
			}
48
		}
49
50
		// (Maybe) set form items.
51
		if ( isset( $data['getpaid-form-items'] ) ) {
52
53
			// Confirm items key.
54
			$form_items = wpinv_clean( $data['getpaid-form-items'] );
55
			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
0 ignored issues
show
Are you sure $form_items of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . /** @scrutinizer ignore-type */ $form_items ) !== $data['getpaid-form-items-key'] ) {
Loading history...
56
				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
57
			}
58
59
			$items    = array();
60
            $item_ids = array();
61
62
            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
63
                if ( ! in_array( $item_id, $item_ids ) ) {
64
                    $item = new GetPaid_Form_Item( $item_id );
65
                    $item->set_quantity( $qty );
66
67
                    if ( empty( $qty ) ) {
68
                        $item->set_allow_quantities( true );
69
                        $item->set_is_required( false );
70
                    }
71
72
					if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
73
						$item->set_is_dynamic_pricing( true );
74
						$item->set_minimum_price( 0 );
75
					}
76
77
                    $item_ids[] = $item->get_id();
78
                    $items[]    = $item;
79
                }
80
            }
81
82
            if ( ! $payment_form->is_default() ) {
83
84
                foreach ( $payment_form->get_items() as $item ) {
85
                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
86
                        $item_ids[] = $item->get_id();
87
                        $items[]    = $item;
88
                    }
89
                }
90
			}
91
92
            $payment_form->set_items( $items );
93
94
		}
95
96
		// Process each individual item.
97
		foreach ( $payment_form->get_items() as $item ) {
98
			$this->process_item( $item, $selected_items, $submission );
99
		}
100
101
	}
102
103
	/**
104
	 * Process a single item.
105
	 *
106
	 * @param GetPaid_Form_Item $item
107
	 * @param array $selected_items
108
	 * @param GetPaid_Payment_Form_Submission $submission
109
	 */
110
	public function process_item( $item, $selected_items, $submission ) {
111
112
		// Abort if this is an optional item and it has not been selected.
113
		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
114
			return;
115
		}
116
117
		// (maybe) let customers change the quantities and prices.
118
		if ( isset( $selected_items[ $item->get_id() ] ) ) {
119
120
			// Maybe change the quantities.
121
			if ( $item->allows_quantities() ) {
122
				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
123
			}
124
125
			// Maybe change the price.
126
			if ( $item->user_can_set_their_price() ) {
127
				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
128
129
				if ( $item->get_minimum_price() > $price ) {
130
					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
131
				}
132
133
				$item->set_price( $price );
134
135
			}
136
		}
137
138
		if ( 0 == $item->get_quantity() ) {
139
			return;
140
		}
141
142
		// Save the item.
143
		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
144
145
	}
146
147
}
148