Issues (6)

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/UserController.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
namespace app\modules\admin\controllers;
4
5
use app\models\UserModel;
6
use app\modules\admin\models\search\UserSearch;
7
use app\traits\FindModelTrait;
8
use Yii;
9
use yii\filters\VerbFilter;
10
use yii\web\Controller;
11
use yii\web\ForbiddenHttpException;
12
use yii2mod\editable\EditableAction;
13
14
/**
15
 * Class UserController
16
 *
17
 * @package app\modules\admin\controllers
18
 */
19
class UserController extends Controller
20
{
21
    use FindModelTrait;
22
23
    /**
24
     * Name of the session key in which the original user id is saved.
25
     */
26
    const ORIGINAL_USER_SESSION_KEY = 'original_user';
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function behaviors(): array
32
    {
33
        return [
34
            'verbs' => [
35
                'class' => VerbFilter::class,
36
                'actions' => [
37
                    'index' => ['get'],
38
                    'create' => ['get', 'post'],
39
                    'update' => ['get', 'post'],
40
                    'delete' => ['post'],
41
                ],
42
            ],
43
        ];
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function actions(): array
50
    {
51
        return [
52
            'edit-user' => [
53
                'class' => EditableAction::class,
54
                'modelClass' => UserModel::class,
55
                'forceCreate' => false,
56
            ],
57
            'index' => [
58
                'class' => 'yii2tech\admin\actions\Index',
59
                'newSearchModel' => function () {
60
                    return new UserSearch();
61
                },
62
            ],
63
            'delete' => [
64
                'class' => 'yii2tech\admin\actions\Delete',
65
                'findModel' => function (int $id) {
66
                    return $this->findModel(UserModel::class, $id);
67
                },
68
                'flash' => Yii::t('app', 'User has been deleted.'),
69
            ],
70
        ];
71
    }
72
73
    /**
74
     * Creates a new user.
75
     *
76
     * If creation is successful, the browser will be redirected to the 'index' page.
77
     *
78
     * @return mixed
79
     */
80
    public function actionCreate()
81
    {
82
        $model = new UserModel(['scenario' => 'create']);
83
84 View Code Duplication
        if ($model->load(Yii::$app->request->post())) {
0 ignored issues
show
This code seems to be duplicated across 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...
85
            if ($model->create()) {
86
                Yii::$app->session->setFlash('success', Yii::t('app', 'User has been created.'));
87
88
                return $this->redirect(['index']);
89
            }
90
        }
91
92
        return $this->render('create', [
93
            'model' => $model,
94
        ]);
95
    }
96
97
    /**
98
     * Updates an existing user.
99
     *
100
     * If update is successful, the browser will be redirected to the 'index' page.
101
     *
102
     * @param int $id
103
     *
104
     * @return mixed
105
     */
106
    public function actionUpdate(int $id)
107
    {
108
        /* @var $model UserModel */
109
        $model = $this->findModel(UserModel::class, $id);
110
111
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
112
            if (!empty($model->plainPassword)) {
113
                $model->setPassword($model->plainPassword);
114
            }
115
            $model->save(false);
116
            Yii::$app->session->setFlash('success', Yii::t('app', 'User has been saved.'));
117
118
            return $this->redirect(['index']);
119
        }
120
121
        return $this->render('update', [
122
            'model' => $model,
123
        ]);
124
    }
125
126
    /**
127
     * Switches to the given user for the rest of the Session.
128
     *
129
     * @param int $id
130
     *
131
     * @throws ForbiddenHttpException
132
     *
133
     * @return string
134
     */
135
    public function actionSwitch(int $id)
136
    {
137
        if (Yii::$app->session->has(self::ORIGINAL_USER_SESSION_KEY)) {
138
            $user = $this->findModel(UserModel::class, Yii::$app->session->get(self::ORIGINAL_USER_SESSION_KEY));
139
            Yii::$app->session->remove(self::ORIGINAL_USER_SESSION_KEY);
140
        } else {
141
            $user = $this->findModel(UserModel::class, $id);
142
            Yii::$app->session->set(self::ORIGINAL_USER_SESSION_KEY, Yii::$app->user->id);
143
        }
144
145
        Yii::$app->user->switchIdentity($user, 3600);
146
147
        return $this->goHome();
148
    }
149
}
150