Issues (115)

Security Analysis    no request data  

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.

lib/roles.php (4 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
use Elgg\Roles\Api;
4
5
/**
6
 * Roles library functions
7
 *
8
 * @package Roles
9
 * @author Andras Szepeshazi
10
 * @copyright Arck Interactive, LLC 2012
11
 * @link http://www.arckinteractive.com/
12
 */
13
14
/**
15
 * Obtains the role of a given user
16
 *
17
 * @param ElggUser $user User entity
18
 * @return ElggRole The role the user belongs to
19
 */
20
function roles_get_role($user = null) {
21
	$user = isset($user) ? $user : elgg_get_logged_in_user_entity();
22
	if ($user instanceof ElggUser) {
0 ignored issues
show
The class ElggUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
23
		return roles()->getRole($user);
24
	}
25
	return roles()->getRoleByName(roles()->filterName(Api::NO_ROLE));
26
}
27
28
/**
29
 * Checks if the user has a specific role
30
 *
31
 * @param ElggUser $user
32
 * @return bool True if the user belongs to the passed role, false otherwise
33
 */
34
function roles_has_role($user = null, $role_name = DEFAULT_ROLE) {
35
	return roles()->hasRole($user, $role_name);
0 ignored issues
show
It seems like $user defined by parameter $user on line 34 can be null; however, Elgg\Roles\Api::hasRole() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
36
}
37
38
/**
39
 * Assigns a role to a particular user
40
 *
41
 * @param ElggRole $role The role to be assigned
42
 * @param ElggUser $user The user the role needs to be assigned to
43
 * @return bool|void True if the role change was successful, false if could not update user role, and null if there was no change in user role
44
 */
45
function roles_set_role($role, $user = null) {
46
	$user = isset($user) ? $user : elgg_get_logged_in_user_entity();
47
	if ($user instanceof ElggUser && $role instanceof ElggRole) {
0 ignored issues
show
The class ElggUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
48
		return roles()->setRole($user, $role);
49
	}
50
	return false;
51
}
52
53
/**
54
 * Gets all role objects
55
 * @return ElggRole[]|false An array of ElggRole objects defined in the system, or false if none found
56
 */
57
function roles_get_all_roles() {
58
	return roles()->getAll();
59
}
60
61
/**
62
 * Gets all non-default role objects
63
 *
64
 * This is used by the role selector view. Default roles (VISITOR_ROLE, ADMIN_ROLE, DEFAULT_ROLE) need to be omitted from
65
 * the list of selectable roles - as default roles are automatically assigned to users based on their Elgg membership type
66
 * 
67
 * @return ElggRole[]|false An array of non-default ElggRole objects defined in the system, or false if none found
68
 */
69
function roles_get_all_selectable_roles() {
70
	return roles()->getSelectable();
71
}
72
73
/**
74
 * Obtains a list of permissions associated with a particular role object
75
 *
76
 * @param ElggRole $role            The role to check for permissions
77
 * @param string   $permission_type The section from the configuration array ('actions', 'menus', 'views', etc.)
78
 * @return array The permission rules for the given role and permission type
79
 */
80
function roles_get_role_permissions($role = null, $permission_type = null) {
81
	$role = isset($role) ? $role : roles_get_role();
82
	return roles()->getPermissions($role, $permission_type);
83
}
84
85
/**
86
 * Caches permissions associated with a role object. Also resolves all role extensions.
87
 *
88
 * @param ElggRole $role The role to cache permissions for
89
 * @return void
90
 */
91
function roles_cache_permissions($role) {
92
	return roles()->cachePermissions($role);
93
}
94
95
/**
96
 * Gets a role object based on it's name
97
 *
98
 * @param string $role_name The name of the role
99
 * @return ElggRole|false An ElggRole object if it could be found based on the name, false otherwise
100
 */
101
function roles_get_role_by_name($role_name) {
102
	return roles()->getRoleByName($role_name);
103
}
104
105
/**
106
 * Resolves the default role for specified or currently logged in user
107
 *
108
 * @param string $role_name The name of the user's role
109
 * @param int    $user_guid GUID of the user whose default role needs to be resolved
110
 * @return string
111
 */
112
function roles_filter_role_name($role_name, $user_guid = null) {
113
	if (!isset($user_guid)) {
114
		$user_guid = elgg_get_logged_in_user_guid();
115
	}
116
	return roles()->filterName($role_name, get_entity($user_guid) ? : null);
117
}
118
119
/**
120
 * Processes the configuration files and generates the appropriate ElggRole objects.
121
 *
122
 * If, for any role definition, there is an already existing role with the same name,
123
 * the role permissions will be updated for the given role object.
124
 * If there is no previously existing, corresponding role object, it will be created now.
125
 *
126
 * @param array $roles_array The roles configuration array
127
 * @return void
128
 */
129
function roles_create_from_config($roles_array) {
130
	return roles()->createFromConfig($roles_array);
131
}
132
133
/**
134
 * Checks if the configuration array has been updated and updates role objects accordingly if needed
135
 * @return void
136
 */
137
function roles_check_update() {
138
	return roles()->checkUpdate();
139
}
140
141
/**
142
 * @deprecated 2.0
143
 */
144
function roles_unregister_menu_item() {
145
	
146
}
147
148
/**
149
 * @deprecated 2.0
150
 */
151
function roles_replace_menu_item() {
152
153
}
154
155
/**
156
 * @deprecated 2.0
157
 */
158
function roles_unregister_menu_item_recursive() {
159
	
160
}
161
162
/**
163
 * @deprecated 2.0
164
 */
165
function roles_replace_menu_item_recursive() {
166
	
167
}
168
169
/**
170
 * @deprecated 2.0
171
 */
172
function roles_find_menu_index() {
173
	
174
}
175
176
/**
177
 * Substitutes dynamic parts of a menu's target URL
178
 *
179
 * @param array $vars An associative array holding the menu permissions
180
 * @return The substituted menu permission array
181
 */
182
function roles_prepare_menu_vars($vars) {
183
	return roles()->prepareMenuVars($vars);
184
}
185
186
/**
187
 * @deprecated 2.0
188
 */
189
function roles_get_menu($menu_name) {
0 ignored issues
show
The parameter $menu_name 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...
190
	
191
}
192
193
/**
194
 * Replaces certain parts of path and URL type definitions with dynamic values
195
 *
196
 * @param string $str The string to operate on
197
 * @return string The updated, substituted string
198
 */
199
function roles_replace_dynamic_paths($str) {
200
	return roles()->replaceDynamicPaths($str);
201
}
202
203
/**
204
 * Checks if a path or URL type rule matches a given path. Also processes regular expressions
205
 *
206
 * @param string $rule The permission rule to check
207
 * @param string $path The path to match against
208
 * @return boole True if the rule matches the path, false otherwise
209
 */
210
function roles_path_match($rule, $path) {
211
	return roles()->matchPath($rule, $path);
212
}
213
214
/**
215
 * Checks if a permission rule should be executed for the current context
216
 *
217
 * @param string  $permission_details The permission rule configuration
218
 * @param boolean $strict             If strict context matching should be used.
219
 * 							          If true, only the last context will be checked for the rule matching.
220
 * 							          If false, any context value in the context stack will be considered.
221
 * @return bool True if the rule should be executed, false otherwise
222
 */
223
function roles_check_context($permission_details, $strict = false) {
224
	return roles()->checkContext($permission_details, $strict);
225
}
226
227
/**
228
 * Updates roles objects to 1.0.1 version
229
 * @return bool
230
 */
231
function roles_update_100_to_101() {
232
233
	// Remove all 'roles_hash' values from plugin settings
234
	// This will force new storage of the configuration array hash
235
	$dbprefix = elgg_get_config('dbprefix');
236
	$statement = "DELETE from {$dbprefix}private_settings WHERE name = 'roles_hash'";
237
	return delete_data($statement);
238
}
239