Issues (114)

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.

protected/models/UserRoles.php (1 issue)

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
/**
4
 * This is the model class for table "user_roles".
5
 *
6
 * The followings are the available columns in table 'user_roles':
7
 * @property integer $id
8
 * @property string $name
9
 * @property string $created
10
 * @property string $updated
11
 *
12
 * The followings are the available model relations:
13
 * @property Users[] $users
14
 */
15
class UserRoles extends CiiModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
18
	/**
19
	 * Returns a key => value array of userRole => bitwise permissions
20
	 *
21
	 * Permissions apply per role, with the exception of publisher and admin, whose permissions apply to everything
22
	 * Note that these permissions only apply to content, and management of CiiMS' settings
23
	 *
24
	 * --------------------------------------------------------------------------------
25
	 * | role/id | manage | publish other | publish | delete | update | create | read |
26
	 * --------------------------------------------------------------------------------
27
	 * |  user/1 |   0    |        0      |    0    |    0   |    0   |    0   |  1   |
28
	 * --------------------------------------------------------------------------------
29
	 * | clb/5   |   0    |        0      |    0    |    0   |    1   |    1   |  1   |
30
	 * --------------------------------------------------------------------------------
31
	 * | auth/7  |   0    |        0      |    1    |    1   |    1   |    1   |  1   |
32
	 * --------------------------------------------------------------------------------
33
	 * | pub/8   |   0    |        1      |    1    |    1   |    1   |    1   |  1   |
34
	 * --------------------------------------------------------------------------------
35
	 * | admin/9 |   1    |        1      |    1    |    1   |    1   |    1   |  1   |
36
	 * --------------------------------------------------------------------------------
37
	 * @return array
38
	 */
39
	public function getPermissions()
40
	{
41
		return array(
42
			'1' => 1,		// User
43
			'2' => 0,		// Pending
44
			'3' => 0,		// Suspended
45
			'5' => 7,		// Collaborator
46
			'7' => 16,		// Author
47
			'8' => 32,		// Publisher
48
			'9' => 64		// Admin
49
		);
50
	}
51
52
	public function isA($roleName, $role=false)
53
	{
54
		if ($role === false)
55
			$role = Yii::app()->user->role;
56
57
		$roleName = strtolower($roleName);
58
59
		switch ($roleName)
60
		{
61
			case 'user':
62
				return $role <= 1;
63
			case 'collaborator':
64
				return $role == 5;
65
			case 'author':
66
				return $role == 7;
67
			case 'publisher':
68
				return $role == 8;
69
			case 'admin':
70
				return $role == 9;
71
		}
72
73
		return false;
74
	}
75
76
	/**
77
	 * Returns the bitwise permissions associated to each activity
78
	 * @return array
79
	 */
80
	public function getActivities()
81
	{
82
		return array(
83
			'read' 			=> 1,
84
			'comment' 		=> 1,
85
			'create' 		=> 3,
86
			'update' 		=> 4,
87
			'modify' 		=> 7,
88
			'delete' 		=> 8,
89
			'publish' 		=> 16,
90
			'publishOther' 	=> 32,
91
			'manage' 		=> 64
92
		);
93
	}
94
95
	/**
96
	 * Determines if a user with a given role has permission to perform a given activity
97
	 * @param string $permission   The permissions we want to lookup
98
	 * @param int 	 $role 			The user role. If not provided, will be applied to the current user
99
	 * @return boolean
100
	 */
101
	public function hasPermission($permission, $role=NULL)
102
	{
103
		if ($role === NULL)
104
		{
105
			if (isset($this->id))
106
				$role = $this->id;
107
			else if (Yii::app()->user->isGuest)
108
				$role = 1;
109
			else
110
				$role = Yii::app()->user->role;
111
		}
112
113
		$permissions = $this->getPermissions();
114
		$activities = $this->getActivities();
115
116
		// If the permission doesn't exist for that role, return false;
117
		if (!isset($permissions[$role]))
118
			return false;
119
120
		return $activities[$permission] <= $permissions[$role];
121
	}
122
123
	/**
124
	 * Returns the static model of the specified AR class.
125
	 * @param string $className active record class name.
126
	 * @return UserRoles the static model class
127
	 */
128
	public static function model($className=__CLASS__)
129
	{
130
		return parent::model($className);
131
	}
132
133
	/**
134
	 * @return string the associated database table name
135
	 */
136
	public function tableName()
137
	{
138
		return 'user_roles';
139
	}
140
141
	/**
142
	 * @return array validation rules for model attributes.
143
	 */
144
	public function rules()
145
	{
146
		// NOTE: you should only define rules for those attributes that
147
		// will receive user inputs.
148
		return array(
149
			array('name', 'required'),
150
			array('name', 'length', 'max'=>100),
151
			// The following rule is used by search().
152
			array('id, name, created, updated', 'safe', 'on'=>'search'),
153
		);
154
	}
155
156
	/**
157
	 * @return array relational rules.
158
	 */
159
	public function relations()
160
	{
161
		// NOTE: you may need to adjust the relation name and the related
162
		// class name for the relations automatically generated below.
163
		return array(
164
			'users' => array(self::HAS_MANY, 'Users', 'user_role'),
165
		);
166
	}
167
168
	/**
169
	 * @return array customized attribute labels (name=>label)
170
	 */
171
	public function attributeLabels()
172
	{
173
		return array(
174
			'id' 	  => Yii::t('ciims.models.UserRoles', 'ID'),
175
			'name' 	  => Yii::t('ciims.models.UserRoles', 'Name'),
176
			'created' => Yii::t('ciims.models.UserRoles', 'Created'),
177
			'updated' => Yii::t('ciims.models.UserRoles', 'Updated'),
178
		);
179
	}
180
181
	/**
182
	 * Retrieves a list of models based on the current search/filter conditions.
183
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
184
	 */
185
	public function search()
186
	{
187
		$criteria=new CDbCriteria;
188
189
		$criteria->compare('id',$this->id);
190
		$criteria->compare('name',$this->name,true);
191
		$criteria->compare('created',$this->created,true);
192
		$criteria->compare('updated',$this->updated,true);
193
194
		return new CActiveDataProvider($this, array(
195
			'criteria'=>$criteria,
196
		));
197
	}
198
}
199