Issues (27)

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.

modules/admin/controllers/UsersController.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
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\web\NotFoundHttpException;
7
use app\controllers\ControllerTrait;
8
use app\models\entity\{User, UserProfile};
9
use app\modules\admin\models\forms\{UserForm, UserProfileForm};
10
use app\modules\admin\models\search\UserSearch;
11
12
class UsersController extends \yii\web\Controller
13
{
14
    use ControllerTrait;
15
16
    public function behaviors()
17
    {
18 6
        return [
19
            'verbs' => [
20
                'class' => 'yii\filters\VerbFilter',
21 6
                'actions' => [
22
                    'set-active' => ['post'],
23
                    'set-block' => ['post'],
24
                    'delete' => ['post'],
25
                    'batch' => ['post'],
26
                    'photo-upload' => ['post'],
27
                    'autocomplete' => ['post'],
28
                ],
29
            ],
30
        ];
31
    }
32
33
    public function actions()
34 6
    {
35
        return [
36
            'batch' => [
37 6
                'class' => 'app\modules\admin\actions\BatchAction',
38
                'modelClass' => User::class,
39
                'actions' => [
40
                    'delete' => [],
41
                    'set-active' => ['status' => User::STATUS_ACTIVE],
42
                    'set-block' => ['status' => User::STATUS_BLOCKED]
43
                ]
44
            ],
45
            'set-active' => [
46
                'class' => 'app\modules\admin\actions\UpdateAttributesAction',
47
                'modelClass' => User::class,
48
                'attributes' => ['status' => User::STATUS_ACTIVE],
49
            ],
50
            'set-block' => [
51
                'class' => 'app\modules\admin\actions\UpdateAttributesAction',
52
                'modelClass' => User::class,
53
                'attributes' => ['status' => User::STATUS_BLOCKED],
54
            ],
55
            'delete' => [
56
                'class' => 'app\modules\admin\actions\DeleteAction',
57
                'modelClass' => User::class,
58
            ],
59
            'photo-upload' => [
60
                'class'     => 'rkit\filemanager\actions\UploadAction',
61
                'modelClass' => UserProfile::class,
62
                'attribute' => 'photo',
63
                'inputName' => 'file',
64
            ],
65
        ];
66
    }
67
68
    public function actionIndex()
69 6
    {
70
        $search = new UserSearch();
71 6
        $provider = $search->search(Yii::$app->request->get());
72 6
        $statuses = User::getStatuses();
73 6
74
        return $this->render('index', [
75 6
            'search' => $search,
76 6
            'provider' => $provider,
77 6
            'statuses' => $statuses,
78 6
            'roles' => Yii::$app->authManager->getRoles()
79 6
        ]);
80
    }
81
82
    public function actionEdit($id = null)
83 3
    {
84
        $model = new UserForm();
85 3
86
        if ($id) {
87 3
            $model->setModel($this->findUser($id));
0 ignored issues
show
$this->findUser($id) of type object<yii\base\Model> is not a sub-type of object<app\models\entity\User>. It seems like you assume a child class of the class yii\base\Model to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
88 2
        }
89
90
        if (Yii::$app->request->isPost) {
91 2
            Yii::$app->response->format = 'json';
92
93
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
94
                $model->save();
95
96
                Yii::$app->session->setFlash('success', Yii::t('app', 'Saved successfully'));
97
                return $this->redirect(['edit', 'id' => $model->id]);
98
            }
99
            return $this->asJsonModelErrors($model);
0 ignored issues
show
$model is of type object<app\modules\admin\models\forms\UserForm>, but the function expects a object<app\controllers\y...ollers\yii\base\Model>>.

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...
100
        }
101
102
        return $this->render('edit', [
103 2
            'model' => $model,
104 2
        ]);
105
    }
106
107
    public function actionProfile($id)
108 2
    {
109
        $model = new UserProfileForm($this->findProfile($id));
0 ignored issues
show
$this->findProfile($id) of type object<yii\base\Model> is not a sub-type of object<app\models\entity\UserProfile>. It seems like you assume a child class of the class yii\base\Model to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
110 2
111 2
        if (Yii::$app->request->isPost) {
112
            Yii::$app->response->format = 'json';
113 1
114
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
115
                $model->save();
116
117
                Yii::$app->session->setFlash('success', Yii::t('app', 'Saved successfully'));
118
                return $this->redirect(['profile', 'id' => $model->user_id]);
119
            }
120
            return $this->asJsonModelErrors($model);
0 ignored issues
show
$model is of type object<app\modules\admin...\forms\UserProfileForm>, but the function expects a object<app\controllers\y...ollers\yii\base\Model>>.

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...
121
        }
122
123
        return $this->render('profile', [
124
            'model' => $model
125 1
        ]);
126 1
    }
127
128
    /**
129
     * Find the model.
130
     * If the model is not found, then 404 HTTP exception will be thrown.
131
     *
132
     * @param int $id
133
     * @return Model
134
     * @throws NotFoundHttpException
135
     */
136
    private function findUser($id): yii\base\Model
137
    {
138
        $model = User::findOne($id);
139
140
        if ($model === null) {
141
            throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
142
        }
143
144
        return $model;
145
    }
146
147
    /**
148
     * Find the model.
149
     * If the model is not found, then 404 HTTP exception will be thrown.
150
     *
151
     * @param int $id
152
     * @return Model
153
     * @throws NotFoundHttpException
154
     */
155
    private function findProfile($id): yii\base\Model
156
    {
157
        $model = UserProfile::findOne($id);
158
159
        if ($model === null) {
160
            throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
161
        }
162
163
        return $model;
164
    }
165
}
166