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.

base/ItemController.php (5 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\base;
4
5
use Yii;
6
use yii\filters\VerbFilter;
7
use yii\rbac\Item;
8
use yii\web\Controller;
9
use yii\web\NotFoundHttpException;
10
use yii\web\Response;
11
use yii2mod\rbac\models\AuthItemModel;
12
use yii2mod\rbac\models\search\AuthItemSearch;
13
14
/**
15
 * Class ItemController
16
 *
17
 * @package yii2mod\rbac\base
18
 */
19
class ItemController extends Controller
20
{
21
    /**
22
     * @var string search class name for auth items search
23
     */
24
    public $searchClass = [
25
        'class' => AuthItemSearch::class,
26
    ];
27
28
    /**
29
     * @var int Type of Auth Item
30
     */
31
    protected $type;
32
33
    /**
34
     * @var array labels use in view
35
     */
36
    protected $labels;
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function behaviors(): array
42
    {
43
        return [
44
            'verbs' => [
45
                'class' => VerbFilter::class,
46
                'actions' => [
47
                    'index' => ['get'],
48
                    'view' => ['get'],
49
                    'create' => ['get', 'post'],
50
                    'update' => ['get', 'post'],
51
                    'delete' => ['post'],
52
                    'assign' => ['post'],
53
                    'remove' => ['post'],
54
                ],
55
            ],
56
            'contentNegotiator' => [
57
                'class' => 'yii\filters\ContentNegotiator',
58
                'only' => ['assign', 'remove'],
59
                'formats' => [
60
                    'application/json' => Response::FORMAT_JSON,
61
                ],
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * Lists of all auth items
68
     *
69
     * @return mixed
70
     */
71
    public function actionIndex()
72
    {
73
        $searchModel = Yii::createObject($this->searchClass);
74
        $searchModel->type = $this->type;
75
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
76
77
        return $this->render('index', [
78
            'dataProvider' => $dataProvider,
79
            'searchModel' => $searchModel,
80
        ]);
81
    }
82
83
    /**
84
     * Displays a single AuthItem model.
85
     *
86
     * @param string $id
87
     *
88
     * @return mixed
89
     */
90
    public function actionView(string $id)
91
    {
92
        $model = $this->findModel($id);
93
94
        return $this->render('view', ['model' => $model]);
95
    }
96
97
    /**
98
     * Creates a new AuthItem model.
99
     *
100
     * If creation is successful, the browser will be redirected to the 'view' page.
101
     *
102
     * @return mixed
103
     */
104 View Code Duplication
    public function actionCreate()
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...
105
    {
106
        $model = new AuthItemModel();
107
        $model->type = $this->type;
108
109
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
110
            Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Item has been saved.'));
111
112
            return $this->redirect(['view', 'id' => $model->name]);
113
        }
114
115
        return $this->render('create', ['model' => $model]);
116
    }
117
118
    /**
119
     * Updates an existing AuthItem model.
120
     *
121
     * If update is successful, the browser will be redirected to the 'view' page.
122
     *
123
     * @param string $id
124
     *
125
     * @return mixed
126
     */
127 View Code Duplication
    public function actionUpdate(string $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...
128
    {
129
        $model = $this->findModel($id);
130
131
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
132
            Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Item has been saved.'));
133
134
            return $this->redirect(['view', 'id' => $model->name]);
135
        }
136
137
        return $this->render('update', ['model' => $model]);
138
    }
139
140
    /**
141
     * Deletes an existing AuthItem model.
142
     *
143
     * If deletion is successful, the browser will be redirected to the 'index' page.
144
     *
145
     * @param string $id
146
     *
147
     * @return mixed
148
     */
149 View Code Duplication
    public function actionDelete(string $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...
150
    {
151
        $model = $this->findModel($id);
152
        Yii::$app->getAuthManager()->remove($model->item);
153
        Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Item has been removed.'));
154
155
        return $this->redirect(['index']);
156
    }
157
158
    /**
159
     * Assign items
160
     *
161
     * @param string $id
162
     *
163
     * @return array
164
     */
165 View Code Duplication
    public function actionAssign(string $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...
166
    {
167
        $items = Yii::$app->getRequest()->post('items', []);
168
        $model = $this->findModel($id);
169
        $model->addChildren($items);
170
171
        return array_merge($model->getItems());
172
    }
173
174
    /**
175
     * Remove items
176
     *
177
     * @param string $id
178
     *
179
     * @return array
180
     */
181 View Code Duplication
    public function actionRemove(string $id): array
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...
182
    {
183
        $items = Yii::$app->getRequest()->post('items', []);
184
        $model = $this->findModel($id);
185
        $model->removeChildren($items);
186
187
        return array_merge($model->getItems());
188
    }
189
190
    /**
191
     * @inheritdoc
192
     */
193
    public function getViewPath(): string
194
    {
195
        return $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'item';
196
    }
197
198
    /**
199
     * @return int
200
     */
201
    public function getType(): int
202
    {
203
        return $this->type;
204
    }
205
206
    /**
207
     * @return array
208
     */
209
    public function getLabels(): array
210
    {
211
        return $this->labels;
212
    }
213
214
    /**
215
     * Finds the AuthItem model based on its primary key value.
216
     *
217
     * If the model is not found, a 404 HTTP exception will be thrown.
218
     *
219
     * @param string $id
220
     *
221
     * @return AuthItemModel the loaded model
222
     *
223
     * @throws NotFoundHttpException if the model cannot be found
224
     */
225
    protected function findModel(string $id): AuthItemModel
226
    {
227
        $auth = Yii::$app->getAuthManager();
228
        $item = $this->type === Item::TYPE_ROLE ? $auth->getRole($id) : $auth->getPermission($id);
229
230
        if (empty($item)) {
231
            throw new NotFoundHttpException(Yii::t('yii2mod.rbac', 'The requested page does not exist.'));
232
        }
233
234
        return new AuthItemModel($item);
235
    }
236
}
237