Issues (73)

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/UserController.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\controllers;
4
5
use Yii;
6
use app\models\User;
7
use app\models\UserLogin;
8
use app\models\Flow;
9
use yii\helpers\ArrayHelper;
10
use yii\data\ActiveDataProvider;
11
use yii\web\Controller;
12
use yii\web\NotFoundHttpException;
13
use yii\filters\VerbFilter;
14
use yii\filters\AccessControl;
15
16
/**
17
 * UserController implements the CRUD actions for User model.
18
 */
19
class UserController extends Controller
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function behaviors()
25
    {
26
        return [
27
            'verbs' => [
28
                'class' => VerbFilter::class,
29
                'actions' => [
30
                    'delete' => ['POST'],
31
                ],
32
            ],
33
            'access' => [
34
                'class' => AccessControl::class,
35
                'only' => ['index', 'view', 'create', 'import', 'delete', 'set-roles'],
36
                'rules' => [
37
                    ['allow' => true, 'actions' => ['index', 'view', 'create', 'delete', 'set-roles'], 'roles' => ['admin']],
38
                    ['allow' => true, 'actions' => ['import'], 'matchCallback' => function () {
39
                        return Yii::$app->params['useLdap'];
40
                    }],
41
                ],
42
            ],
43
        ];
44
    }
45
46
    /**
47
     * Lists all User models.
48
     *
49
     * @return string render
50
     */
51 View Code Duplication
    public function actionIndex()
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...
52
    {
53
        $dataProvider = new ActiveDataProvider([
54
            'query' => User::find(),
55
        ]);
56
57
        return $this->render('index', [
58
            'dataProvider' => $dataProvider,
59
        ]);
60
    }
61
62
    /**
63
     * Displays a single User model.
64
     *
65
     * @param string $id
66
     *
67
     * @return string render
68
     */
69
    public function actionView($id)
70
    {
71
        return $this->render('view', [
72
            'model' => $this->findModel($id),
73
        ]);
74
    }
75
76
    /**
77
     * Creates a new User model.
78
     * If creation is successful, the browser will be redirected to the 'view' page.
79
     *
80
     * @return \yii\web\Response|string redirect or render
81
     */
82 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...
83
    {
84
        $model = new UserLogin();
85
86
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
87
            if (!User::findIdentity($model->username)) {
88
                if (($user = User::create($model->username, $model->password)) !== null) {
89
                    return $this->redirect(['view', 'id' => $user->getId()]);
90
                } else {
91
                    $model->addError('username', Yii::t('app', 'User creation failed'));
92
                }
93
            } else {
94
                $model->addError('username', Yii::t('app', 'This user is already registered'));
95
            }
96
        }
97
98
        return $this->render('create', [
99
            'model' => $model,
100
        ]);
101
    }
102
103
    /**
104
     * Import user from LDAP and save it.
105
     *
106
     * @return \yii\web\Response|string redirect or render
107
     */
108 View Code Duplication
    public function actionImport()
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...
109
    {
110
        $model = new UserLogin();
111
112
        if ($model->load(Yii::$app->request->post()) && $model->validate(['username'])) {
113
            if (!User::findOne($model->username)) {
114
                if (($user = User::findInLdap($model->username)) !== null) {
115
                    $user->save(false);
116
117
                    return $this->redirect(['view', 'id' => $user->username]);
118
                } else {
119
                    $model->addError('username', Yii::t('app', 'This user doesn\'t exist in LDAP'));
120
                }
121
            } else {
122
                $model->addError('username', Yii::t('app', 'This user is already registered'));
123
            }
124
        }
125
126
        return $this->render('import', [
127
            'model' => $model,
128
        ]);
129
    }
130
131
    /**
132
     * Deletes an existing User model.
133
     * If deletion is successful, the browser will be redirected to the 'index' page.
134
     *
135
     * @param string $id
136
     *
137
     * @return \yii\web\Response
138
     */
139
    public function actionDelete($id)
140
    {
141
        $this->findModel($id)->delete();
142
143
        return $this->redirect(['index']);
144
    }
145
146
    /**
147
     * Set roles and flows for a specific user.
148
     *
149
     * @param string $id user id
150
     *
151
     * @return \yii\web\Response|string redirect or render
152
     */
153
    public function actionSetRoles($id)
154
    {
155
        $model = $this->findModel($id);
156
        $auth = Yii::$app->authManager;
157
158
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
159
            return $this->redirect(['view', 'id' => $model->username]);
160
        }
161
162
        $roles = $auth->getRoles();
163
        $rolesArray = ['' => Yii::t('app', 'None')];
164
        $flowableRoles = [];
165
        foreach ($roles as $name => $role) {
166
            $rolesArray[$name] = Yii::t('app', $name);
167
            if ($role->data && array_key_exists('requireFlow', $role->data)) {
168
                $flowableRoles[] = $name;
169
            }
170
        }
171
172
        $flows = ArrayHelper::map(Flow::find()->all(), 'id', 'name');
173
174
        return $this->render('set-roles', [
175
            'model' => $model,
176
            'roles' => $rolesArray,
177
            'flows' => $flows,
178
            'flowableRoles' => $flowableRoles,
179
        ]);
180
    }
181
182
    /**
183
     * Finds the User model based on its primary key value.
184
     * If the model is not found, a 404 HTTP exception will be thrown.
185
     *
186
     * @param string $id
187
     *
188
     * @return User the loaded model
189
     *
190
     * @throws NotFoundHttpException if the model cannot be found
191
     */
192 View Code Duplication
    protected function findModel($id)
193
    {
194
        if (($model = User::findOne($id)) !== null) {
0 ignored issues
show
Bug Compatibility introduced by
The expression \app\models\User::findOne($id); of type yii\db\ActiveRecordInterface|array|null adds the type array to the return on line 195 which is incompatible with the return type documented by app\controllers\UserController::findModel of type app\models\User.
Loading history...
195
            return $model;
196
        } else {
197
            throw new NotFoundHttpException(Yii::t('app', 'The requested user does not exist.'));
198
        }
199
    }
200
}
201