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/class-give-roles.php (8 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
 * Roles and Capabilities
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Roles
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
 * Give_Roles Class
19
 *
20
 * This class handles the role creation and assignment of capabilities for those roles.
21
 *
22
 * These roles let us have Give Accountants, Give Workers, etc, each of whom can do
23
 * certain things within the plugin.
24
 *
25
 * @since 1.0
26
 */
27
class Give_Roles {
28
29 18
	/**
30
	 * Class Constructor
31 18
	 *
32 18
	 * Set up the Give Roles Class.
33
	 *
34
	 * @since  1.0
35
	 * @access public
36
	 */
37
	public function __construct() {
38
		add_filter( 'give_map_meta_cap', array( $this, 'meta_caps' ), 10, 4 );
39
		add_filter( 'woocommerce_disable_admin_bar', array( $this, 'manage_admin_dashboard' ), 10, 1 );
40
		add_filter( 'woocommerce_prevent_admin_access', array( $this, 'manage_admin_dashboard' ), 10 );
41 18
	}
42 18
43 18
	/**
44 18
	 * Add Roles
45 18
	 *
46 18
	 * Add new shop roles with default WordPress capabilities.
47 18
	 *
48 18
	 * @since  1.0
49 18
	 * @access public
50 18
	 *
51 18
	 * @return void
52 18
	 */
53 18
	public function add_roles() {
54 18
		add_role( 'give_manager', __( 'Give Manager', 'give' ), array(
0 ignored issues
show
Use wpcom_vip_add_role() instead of add_role()
Loading history...
55 18
			'read'                   => true,
56 18
			'edit_posts'             => true,
57 18
			'delete_posts'           => true,
58 18
			'unfiltered_html'        => true,
59 18
			'upload_files'           => true,
60 18
			'export'                 => false,
61 18
			'import'                 => false,
62 18
			'delete_others_pages'    => false,
63 18
			'delete_others_posts'    => false,
64 18
			'delete_pages'           => true,
65 18
			'delete_private_pages'   => true,
66 18
			'delete_private_posts'   => true,
67 18
			'delete_published_pages' => true,
68 18
			'delete_published_posts' => true,
69 18
			'edit_others_pages'      => false,
70
			'edit_others_posts'      => false,
71 18
			'edit_pages'             => true,
72
			'edit_private_pages'     => true,
73 18
			'edit_private_posts'     => true,
74 18
			'edit_published_pages'   => true,
75 18
			'edit_published_posts'   => true,
76
			'manage_categories'      => false,
77 18
			'manage_links'           => true,
78
			'moderate_comments'      => true,
79 18
			'publish_pages'          => true,
80 18
			'publish_posts'          => true,
81 18
			'read_private_pages'     => true,
82 18
			'read_private_posts'     => true,
83
		) );
84 18
85
		add_role( 'give_accountant', __( 'Give Accountant', 'give' ), array(
0 ignored issues
show
Use wpcom_vip_add_role() instead of add_role()
Loading history...
86 18
			'read'         => true,
87
			'edit_posts'   => false,
88
			'delete_posts' => false,
89
		) );
90
91
		add_role( 'give_worker', __( 'Give Worker', 'give' ), array(
0 ignored issues
show
Use wpcom_vip_add_role() instead of add_role()
Loading history...
92
			'read'         => true,
93
			'edit_posts'   => true,
94
			'edit_pages'   => true,
95
			'upload_files' => true,
96 18
			'delete_posts' => false,
97 18
		) );
98
99 18
		add_role( 'give_donor', __( 'Give Donor', 'give' ), array(
0 ignored issues
show
Use wpcom_vip_add_role() instead of add_role()
Loading history...
100 18
			'read' => true,
101
		) );
102
103 18
	}
104
105 18
	/**
106 18
	 * Add Capabilities
107 18
	 *
108 18
	 * Add new shop-specific capabilities.
109 18
	 *
110
	 * @since  1.0
111 18
	 * @access public
112 18
	 *
113 18
	 * @global WP_Roles $wp_roles
114 18
	 *
115
	 * @return void
116
	 */
117 18 View Code Duplication
	public function add_caps() {
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...
118 18
		global $wp_roles;
119 18
120 18
		if ( class_exists( 'WP_Roles' ) ) {
121 18
			if ( ! isset( $wp_roles ) ) {
122 18
				$wp_roles = new WP_Roles();
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
123 18
			}
124 18
		}
125
126 18
		if ( is_object( $wp_roles ) ) {
127 18
			$wp_roles->add_cap( 'give_manager', 'view_give_reports' );
128 18
			$wp_roles->add_cap( 'give_manager', 'view_give_sensitive_data' );
129 18
			$wp_roles->add_cap( 'give_manager', 'export_give_reports' );
130 18
			$wp_roles->add_cap( 'give_manager', 'manage_give_settings' );
131
			$wp_roles->add_cap( 'give_manager', 'view_give_payments' );
132 18
133 18
			$wp_roles->add_cap( 'administrator', 'view_give_reports' );
134
			$wp_roles->add_cap( 'administrator', 'view_give_sensitive_data' );
135
			$wp_roles->add_cap( 'administrator', 'export_give_reports' );
136
			$wp_roles->add_cap( 'administrator', 'manage_give_settings' );
137
			$wp_roles->add_cap( 'administrator', 'view_give_payments' );
138
139
			// Add the main post type capabilities.
140
			$capabilities = $this->get_core_caps();
141
			foreach ( $capabilities as $cap_group ) {
142 18
				foreach ( $cap_group as $cap ) {
143 18
					$wp_roles->add_cap( 'administrator', $cap );
144
					$wp_roles->add_cap( 'give_manager', $cap );
145 18
				}
146
			}
147 18
148 18
			// Add Capabilities to Give Workers User Role.
149
			$wp_roles->add_cap( 'give_worker', 'edit_give_payments' );
150 18
			$wp_roles->add_cap( 'give_worker', 'delete_give_forms' );
151 18
			$wp_roles->add_cap( 'give_worker', 'delete_others_give_forms' );
152 18
			$wp_roles->add_cap( 'give_worker', 'delete_private_give_forms' );
153 18
			$wp_roles->add_cap( 'give_worker', 'delete_published_give_forms' );
154 18
			$wp_roles->add_cap( 'give_worker', 'edit_give_forms' );
155 18
			$wp_roles->add_cap( 'give_worker', 'edit_others_give_forms' );
156 18
			$wp_roles->add_cap( 'give_worker', 'edit_private_give_forms' );
157 18
			$wp_roles->add_cap( 'give_worker', 'edit_published_give_forms' );
158 18
			$wp_roles->add_cap( 'give_worker', 'publish_give_forms' );
159 18
			$wp_roles->add_cap( 'give_worker', 'read_private_give_forms' );
160 18
161 18
			// Add Capabilities to Give Accountant User Role.
162 18
			$wp_roles->add_cap( 'give_accountant', 'edit_give_forms' );
163
			$wp_roles->add_cap( 'give_accountant', 'read_private_give_forms' );
164
			$wp_roles->add_cap( 'give_accountant', 'view_give_reports' );
165 18
			$wp_roles->add_cap( 'give_accountant', 'export_give_reports' );
166 18
			$wp_roles->add_cap( 'give_accountant', 'edit_give_payments' );
167 18
			$wp_roles->add_cap( 'give_accountant', 'view_give_payments' );
168 18
169
		}
170
	}
171 18
172 18
	/**
173 18
	 * Get Core Capabilities
174
	 *
175 18
	 * Retrieve core post type capabilities.
176
	 *
177
	 * @since  1.0
178
	 * @access public
179
	 *
180
	 * @return array $capabilities Core post type capabilities.
181
	 */
182
	public function get_core_caps() {
183
		$capabilities = array();
184
185
		$capability_types = array( 'give_form', 'give_payment' );
186
187
		foreach ( $capability_types as $capability_type ) {
188
			$capabilities[ $capability_type ] = array(
189
				// Post type.
190
				"edit_{$capability_type}",
191
				"read_{$capability_type}",
192
				"delete_{$capability_type}",
193
				"edit_{$capability_type}s",
194
				"edit_others_{$capability_type}s",
195
				"publish_{$capability_type}s",
196
				"read_private_{$capability_type}s",
197
				"delete_{$capability_type}s",
198
				"delete_private_{$capability_type}s",
199
				"delete_published_{$capability_type}s",
200
				"delete_others_{$capability_type}s",
201
				"edit_private_{$capability_type}s",
202
				"edit_published_{$capability_type}s",
203
204
				// Terms / taxonomies.
205
				"manage_{$capability_type}_terms",
206
				"edit_{$capability_type}_terms",
207
				"delete_{$capability_type}_terms",
208
				"assign_{$capability_type}_terms",
209
210
				// Custom capabilities.
211
				"view_{$capability_type}_stats",
212
				"import_{$capability_type}s",
213
			);
214
		}
215
216
		return $capabilities;
217
	}
218
219
	/**
220
	 * Meta Capabilities
221
	 *
222
	 * Map meta capabilities to primitive capabilities.
223
	 *
224
	 * @since  1.0
225
	 * @access public
226
	 *
227
	 * @param  array  $caps    Returns the user's actual capabilities.
228
	 * @param  string $cap     Capability name.
229
	 * @param  int    $user_id The user ID.
230
	 * @param  array  $args    Adds the context to the cap. Typically the object ID.
231
	 *
232
	 * @return array  $caps    Meta capabilities.
233
	 */
234
	public function meta_caps( $caps, $cap, $user_id, $args ) {
235
236
		switch ( $cap ) {
237
238
			case 'view_give_form_stats' :
239
240
				if ( empty( $args[0] ) ) {
241
					break;
242
				}
243
244
				$form = get_post( $args[0] );
245
				if ( empty( $form ) ) {
246
					break;
247
				}
248
249
				if ( user_can( $user_id, 'view_give_reports' ) || $user_id == $form->post_author ) {
250
					$caps = array();
251
				}
252
253
				break;
254
		}
255
256
		return $caps;
257
258
	}
259
260
	/**
261
	 * Remove Capabilities
262
	 *
263
	 * Remove core post type capabilities (called on uninstall).
264
	 *
265
	 * @since  1.0
266
	 * @access public
267
	 *
268
	 * @global WP_Roles $wp_roles
269
	 *
270
	 * @return void
271
	 */
272 View Code Duplication
	public function remove_caps() {
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...
273
274
		global $wp_roles;
275
276
		if ( class_exists( 'WP_Roles' ) ) {
277
			if ( ! isset( $wp_roles ) ) {
278
				$wp_roles = new WP_Roles();
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
279
			}
280
		}
281
282
		if ( is_object( $wp_roles ) ) {
283
			// Give Manager Capabilities.
284
			$wp_roles->remove_cap( 'give_manager', 'view_give_reports' );
285
			$wp_roles->remove_cap( 'give_manager', 'view_give_sensitive_data' );
286
			$wp_roles->remove_cap( 'give_manager', 'export_give_reports' );
287
			$wp_roles->remove_cap( 'give_manager', 'manage_give_settings' );
288
289
			// Site Administrator Capabilities.
290
			$wp_roles->remove_cap( 'administrator', 'view_give_reports' );
291
			$wp_roles->remove_cap( 'administrator', 'view_give_sensitive_data' );
292
			$wp_roles->remove_cap( 'administrator', 'export_give_reports' );
293
			$wp_roles->remove_cap( 'administrator', 'manage_give_settings' );
294
			$wp_roles->remove_cap( 'administrator', 'view_give_payments' );
295
296
			// Remove the Main Post Type Capabilities.
297
			$capabilities = $this->get_core_caps();
298
299
			foreach ( $capabilities as $cap_group ) {
300
				foreach ( $cap_group as $cap ) {
301
					$wp_roles->remove_cap( 'give_manager', $cap );
302
					$wp_roles->remove_cap( 'administrator', $cap );
303
304
				}
305
			}
306
307
			// Remove capabilities from the Give Worker role.
308
			$wp_roles->remove_cap( 'give_worker', 'edit_give_payments' );
309
			$wp_roles->remove_cap( 'give_worker', 'delete_give_forms' );
310
			$wp_roles->remove_cap( 'give_worker', 'delete_others_give_forms' );
311
			$wp_roles->remove_cap( 'give_worker', 'delete_private_give_forms' );
312
			$wp_roles->remove_cap( 'give_worker', 'delete_published_give_forms' );
313
			$wp_roles->remove_cap( 'give_worker', 'edit_give_forms' );
314
			$wp_roles->remove_cap( 'give_worker', 'edit_others_give_forms' );
315
			$wp_roles->remove_cap( 'give_worker', 'edit_private_give_forms' );
316
			$wp_roles->remove_cap( 'give_worker', 'edit_published_give_forms' );
317
			$wp_roles->remove_cap( 'give_worker', 'publish_give_forms' );
318
			$wp_roles->remove_cap( 'give_worker', 'read_private_give_forms' );
319
320
			// Remove Capabilities from Give Accountant User Role.
321
			$wp_roles->remove_cap( 'give_accountant', 'edit_give_forms' );
322
			$wp_roles->remove_cap( 'give_accountant', 'read_private_give_forms' );
323
			$wp_roles->remove_cap( 'give_accountant', 'view_give_reports' );
324
			$wp_roles->remove_cap( 'give_accountant', 'export_give_reports' );
325
			$wp_roles->remove_cap( 'give_accountant', 'edit_give_payments' );
326
			$wp_roles->remove_cap( 'give_accountant', 'view_give_payments' );
327
328
		}
329
	}
330
331
	/**
332
	 * Allow admin dashboard to User with Give Accountant Role.
333
	 *
334
	 * Note: WooCommerce doesn't allow the user to access the WP dashboard who holds "Give Accountant" role.
335
	 *
336
	 * @since 1.8.14
337
	 * @updated 1.8.18 - Fixed Give conflicting by not returning $show_admin_bar https://github.com/WordImpress/Give/issues/2539
338
	 *
339
	 * @param bool
340
	 *
341
	 * @return bool
342
	 */
343
	public function manage_admin_dashboard($show_admin_bar) {
344
345
		// Get the current logged user.
346
		$current_user = wp_get_current_user();
347
348
		// If user with "Give Accountant" user role is logged-in .
349
		if ( 0 !== $current_user->ID && in_array( 'give_accountant', (array) $current_user->roles, true ) ) {
350
351
			// Return false, means no prevention.
352
			return false;
353
		}
354
355
		return $show_admin_bar;
356
357
	}
358
}
359