Issues (4296)

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/emails/template.php (15 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
 * Email Template
4
 *
5
 * @package     Give
6
 * @subpackage  Emails
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Gets all the email templates that have been registered. The list is extendable
19
 * and more templates can be added.
20
 *
21
 * This is simply a wrapper to Give_Email_Templates->get_templates()
22
 *
23
 * @since 1.0
24
 * @return array $templates All the registered email templates.
25
 */
26
function give_get_email_templates() {
27
	$templates = new Give_Emails;
28
29
	return $templates->get_templates();
30
}
31
32
/**
33
 * Email Template Tags.
34
 * @todo Modify this function to remove payment id dependency.
35
 *
36
 * @since 1.0
37
 *
38
 * @param string $message      Message with the template tags.
39
 * @param array  $payment_data Payment Data.
40
 * @param int    $payment_id   Payment ID.
41
 * @param bool   $admin_notice Whether or not this is a notification email.
42
 *
43
 * @return string $message Fully formatted message
44
 */
45
function give_email_template_tags( $message, $payment_data, $payment_id, $admin_notice = false ) {
0 ignored issues
show
The parameter $payment_data 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...
The parameter $admin_notice 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...
46
	return give_do_email_tags( $message, $payment_id );
47
}
48
49
/**
50
 * Email Preview Template Tags.
51
 *
52
 * Provides sample content for the preview email functionality within settings > email.
53
 *
54
 * @since 1.0
55
 *
56
 * @param string $message Email message with template tags
57
 *
58
 * @return string $message Fully formatted message
59
 */
60
function give_email_preview_template_tags( $message ) {
61
62
	$price = give_currency_filter( give_format_amount( 10.50, array( 'sanitize' => false ) ) );
63
64
	$gateway = 'PayPal';
65
66
	$receipt_id = strtolower( md5( uniqid() ) );
67
68
	$payment_id = rand( 1, 100 );
69
	$receipt_link_url = esc_url( add_query_arg( array( 'payment_key' => $receipt_id ), give_get_history_page_uri() ) );
70
71
	$receipt_link     = sprintf(
72
		'<a href="%1$s">%2$s</a>',
73
		$receipt_link_url,
74
		esc_html__( 'View the receipt in your browser &raquo;', 'give' )
75
	);
76
77
	// Set user.
78
	$user = wp_get_current_user();
79
80
	$message = str_replace( '{name}', $user->display_name, $message );
81
	$message = str_replace( '{fullname}', $user->display_name, $message );
82
	$message = str_replace( '{username}', $user->user_login, $message );
83
	$message = str_replace( '{user_email}', $user->user_email, $message );
84
	$message = str_replace( '{billing_address}', "123 Test Street, Unit 222\nSomewhere Town, CA, 92101", $message );
85
	$message = str_replace( '{date}', date( give_date_format(), current_time( 'timestamp' ) ), $message );
86
	$message = str_replace( '{amount}', $price, $message );
87
	$message = str_replace( '{price}', $price, $message );
88
	$message = str_replace( '{donation}', esc_html__( 'Sample Donation Form Title', 'give' ), $message );
89
	$message = str_replace( '{form_title}', esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ), $message );
90
	$message = str_replace( '{receipt_id}', $receipt_id, $message );
91
	$message = str_replace( '{payment_method}', $gateway, $message );
92
	$message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message );
93
	$message = str_replace( '{payment_id}', $payment_id, $message );
94
	$message = str_replace( '{receipt_link}', $receipt_link, $message );
95
	$message = str_replace( '{receipt_link_url}', $receipt_link_url, $message );
96
	$message = str_replace( '{pdf_receipt}', '<a href="#">Download Receipt</a>', $message );
97
98
	return wpautop( apply_filters( 'give_email_preview_template_tags', $message ) );
99
}
100
101
102
103
/**
104
 * Output Email Template Preview Buttons.
105
 *
106
 * @access private
107
 * @since  1.0
108
 * @since  1.8 Field arguments param added.
109
 *
110
 * @param array $field Field arguments.
111
 *
112
 * @return array
113
 */
114
function give_email_preview_buttons_callback( $field ) {
115
	$field_id = str_replace( '_preview_buttons', '', $field['id'] );
116
117
	ob_start();
118
119
	echo sprintf(
0 ignored issues
show
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
120
		'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
121
		wp_nonce_url(
122
			add_query_arg(
123
				array( 'give_action' => 'preview_email', 'email_type' => $field_id ),
124
				home_url()
125
			), 'give-preview-email'
126
		),
127
		$field['name']
128
	);
129
130
	echo sprintf(
0 ignored issues
show
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
131
		' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
132
		wp_nonce_url(
133
				add_query_arg( array(
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
134
			'give_action'  => 'send_preview_email',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 12.
Loading history...
135
			'email_type' => $field_id,
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 12.
Loading history...
136
			'give-messages[]' => 'sent-test-email',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 12.
Loading history...
137
		) ), 'give-send-preview-email' ),
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 8.
Loading history...
138
		esc_attr__( 'Send Test Email.', 'give' ),
139
		esc_html__( 'Send Test Email', 'give' )
140
	);
141
142
	echo ob_get_clean();
0 ignored issues
show
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
143
}
144
145
146
/**
147
 * Give Preview Email Header.
148
 *
149
 * Displays a header bar with the ability to change donations to preview actual data within the preview. Will not display if
150
 *
151
 * @since 1.6
152
 *
153
 */
154
function give_get_preview_email_header() {
155
156
	//Payment receipt switcher
157
	$payment_count = give_count_payments()->publish;
158
	$payment_id    = give_check_variable( give_clean( $_GET ), 'isset', 0, 'preview_id' );
0 ignored issues
show
0 is of type integer, but the function expects a boolean.

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...
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
159
160
	if ( $payment_count <= 0 ) {
161
		return false;
162
	}
163
164
	//Get payments.
165
	$donations = new Give_Payments_Query( array(
166
		'number' => 100,
167
		'output' => '',
168
		'fields' => 'ids'
169
	) );
170
	$donations = $donations->get_payments();
171
	$options  = array();
172
173
	// Default option.
174
	$options[0] = esc_html__( 'No donations found.', 'give' );
175
176
	//Provide nice human readable options.
177
	if ( $donations ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $donations of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
178
		$options[0] = esc_html__( '- Select a donation -', 'give' );
179
		foreach ( $donations as $donation_id ) {
180
181
			$options[ $donation_id ] = sprintf(
182
				'#%1$s - %2$s - %3$s',
183 42
				$donation_id,
184
				give_get_donation_donor_email( $donation_id ),
185 42
				get_the_title( $donation_id )
186
			);
187 42
		}
188
	}
189 42
190
	//Start constructing HTML output.
191 42
	$transaction_header = '<div style="margin:0;padding:10px 0;width:100%;background-color:#FFF;border-bottom:1px solid #eee; text-align:center;">';
192
193 42
	// Remove payment id query param if set from request url.
194
	$request_url_data = wp_parse_url( $_SERVER['REQUEST_URI'] );
0 ignored issues
show
Detected usage of a non-validated input variable: $_SERVER
Loading history...
Detected usage of a non-sanitized input variable: $_SERVER
Loading history...
195
	$query            = $request_url_data['query'];
196
	$query            = remove_query_arg( array( 'preview_id' ), $query );
197
198
	$request_url = home_url( '/?' . str_replace( '', '', $query ) );
199
200
	$transaction_header .= '<script>
201
				 function change_preview(){
202
				  var transactions = document.getElementById("give_preview_email_payment_id");
203
			        var selected_trans = transactions.options[transactions.selectedIndex];
204
				        if (selected_trans){
205
				            var url_string = "' . $request_url . '&preview_id=" + selected_trans.value;
206
				                window.location = url_string;
207
				        }
208
				    }
209
			    </script>';
210 42
211
	$transaction_header .= '<label for="give_preview_email_payment_id" style="font-size:12px;color:#333;margin:0 4px 0 0;">' . esc_html__( 'Preview email with a donation:', 'give' ) . '</label>';
212 42
213 42
	//The select field with 100 latest transactions
214
	$transaction_header .= Give()->html->select( array(
215 42
		'name'             => 'preview_email_payment_id',
216 41
		'selected'         => $payment_id,
217 41
		'id'               => 'give_preview_email_payment_id',
218 42
		'class'            => 'give-preview-email-payment-id',
219 1
		'options'          => $options,
220 1
		'chosen'           => false,
221
		'select_atts'      => 'onchange="change_preview()"',
222
		'show_option_all'  => false,
223
		'show_option_none' => false,
224 42
	) );
225
226 42
	//Closing tag
227 42
	$transaction_header .= '</div>';
228
229 42
	return apply_filters( 'give_preview_email_receipt_header', $transaction_header );
230 42
231
}
232