Issues (65)

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.

controllers/AssignmentController.php (3 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
namespace yii2mod\rbac\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use yii\web\NotFoundHttpException;
8
use yii\web\Response;
9
use yii2mod\rbac\models\AssignmentModel;
10
use yii2mod\rbac\models\search\AssignmentSearch;
11
12
/**
13
 * Class AssignmentController
14
 *
15
 * @package yii2mod\rbac\controllers
16
 */
17
class AssignmentController extends Controller
18
{
19
    /**
20
     * @var \yii\web\IdentityInterface the class name of the [[identity]] object
21
     */
22
    public $userIdentityClass;
23
24
    /**
25
     * @var string search class name for assignments search
26
     */
27
    public $searchClass = [
28
        'class' => AssignmentSearch::class,
29
    ];
30
31
    /**
32
     * @var string id column name
33
     */
34
    public $idField = 'id';
35
36
    /**
37
     * @var string username column name
38
     */
39
    public $usernameField = 'username';
40
41
    /**
42
     * @var array assignments GridView columns
43
     */
44
    public $gridViewColumns = [];
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function init()
50
    {
51
        parent::init();
52
53
        if ($this->userIdentityClass === null) {
54
            $this->userIdentityClass = Yii::$app->user->identityClass;
55
        }
56
57
        if (empty($this->gridViewColumns)) {
58
            $this->gridViewColumns = [
59
                $this->idField,
60
                $this->usernameField,
61
            ];
62
        }
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function behaviors(): array
69
    {
70
        return [
71
            'verbs' => [
72
                'class' => 'yii\filters\VerbFilter',
73
                'actions' => [
74
                    'index' => ['get'],
75
                    'view' => ['get'],
76
                    'assign' => ['post'],
77
                    'remove' => ['post'],
78
                ],
79
            ],
80
            'contentNegotiator' => [
81
                'class' => 'yii\filters\ContentNegotiator',
82
                'only' => ['assign', 'remove'],
83
                'formats' => [
84
                    'application/json' => Response::FORMAT_JSON,
85
                ],
86
            ],
87
        ];
88
    }
89
90
    /**
91
     * List of all assignments
92
     *
93
     * @return string
94
     */
95
    public function actionIndex()
96
    {
97
        /* @var AssignmentSearch */
98
        $searchModel = Yii::createObject($this->searchClass);
99
100
        if ($searchModel instanceof AssignmentSearch) {
101
            $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $this->userIdentityClass, $this->idField, $this->usernameField);
0 ignored issues
show
$this->userIdentityClass is of type object<yii\web\IdentityInterface>, but the function expects a object<yii\db\ActiveRecord>.

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...
102
        } else {
103
            $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
104
        }
105
106
        return $this->render('index', [
107
            'dataProvider' => $dataProvider,
108
            'searchModel' => $searchModel,
109
            'gridViewColumns' => $this->gridViewColumns,
110
        ]);
111
    }
112
113
    /**
114
     * Displays a single Assignment model.
115
     *
116
     * @param int $id
117
     *
118
     * @return mixed
119
     */
120
    public function actionView(int $id)
121
    {
122
        $model = $this->findModel($id);
123
124
        return $this->render('view', [
125
            'model' => $model,
126
            'usernameField' => $this->usernameField,
127
        ]);
128
    }
129
130
    /**
131
     * Assign items
132
     *
133
     * @param int $id
134
     *
135
     * @return array
136
     */
137 View Code Duplication
    public function actionAssign(int $id)
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...
138
    {
139
        $items = Yii::$app->getRequest()->post('items', []);
140
        $assignmentModel = $this->findModel($id);
141
        $assignmentModel->assign($items);
142
143
        return $assignmentModel->getItems();
144
    }
145
146
    /**
147
     * Remove items
148
     *
149
     * @param int $id
150
     *
151
     * @return array
152
     */
153 View Code Duplication
    public function actionRemove(int $id)
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...
154
    {
155
        $items = Yii::$app->getRequest()->post('items', []);
156
        $assignmentModel = $this->findModel($id);
157
        $assignmentModel->revoke($items);
158
159
        return $assignmentModel->getItems();
160
    }
161
162
    /**
163
     * Finds the Assignment model based on its primary key value.
164
     * If the model is not found, a 404 HTTP exception will be thrown.
165
     *
166
     * @param int $id
167
     *
168
     * @return AssignmentModel the loaded model
169
     *
170
     * @throws NotFoundHttpException if the model cannot be found
171
     */
172
    protected function findModel(int $id)
173
    {
174
        $class = $this->userIdentityClass;
175
176
        if (($user = $class::findIdentity($id)) !== null) {
177
            return new AssignmentModel($user);
178
        }
179
180
        throw new NotFoundHttpException(Yii::t('yii2mod.rbac', 'The requested page does not exist.'));
181
    }
182
}
183