Issues (102)

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.

commands/DefaultController.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 inblank\activeuser\commands;
4
5
use inblank\activeuser\components\ConsoleController;
6
use inblank\activeuser\traits\CommonTrait;
7
use Yii;
8
use yii\helpers\Console;
9
10
/**
11
 * Managing user accounts
12
 * @package inblank\activeuser\commands
13
 */
14
class DefaultController extends ConsoleController
15
{
16
    use CommonTrait;
17
18
    /** @var bool whether to send email about action. If not set use module's settings */
19
    public $sendEmail = false;
20
21
    /** @inheritdoc */
22
    public function options($actionID)
23
    {
24
        return ['sendEmail'];
25
    }
26
27
    /**
28
     * Create a new user
29
     * @param string $email user email
30
     * @param string $name user name
31
     * @param string|null $password optional user password. If not set will be generated automatically
32
     * @throws \yii\base\InvalidConfigException
33
     */
34
    public function actionCreate($email = null, $name = null, $password = null)
35
    {
36
        /** @var \inblank\activeuser\models\User $user */
37
        $user = Yii::createObject(self::di('User'));
0 ignored issues
show
self::di('User') is of type *, but the function expects a callable.

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...
38
        $this->getModule()->registrationFields = ['name'];
39
        $user->setAttributes(compact('email', 'name', 'password'), false);
40
        if (!$user->validate(['email', 'name'])) {
41
            $this->showUsage('email,name', 'password', $user->getErrors());
42
        }
43
        $nameString = $this->ansiFormat($name, Console::FG_GREEN);
44
        $emailString = $this->ansiFormat($email, Console::FG_GREEN);
45
        $this->confirmAction(Yii::t("activeuser_backend", "Create new user {nameString} with email {emailString}?", [
46
            'emailString' => $emailString,
47
            'nameString' => $nameString,
48
        ]));
49
        // create user
50
        if (!$user->create($this->sendEmail)) {
51
            $this->showErrors($user->getErrors());
52
        }
53
        $passwordString = $this->ansiFormat($user->password, Console::FG_GREEN);
54
        $info = Yii::t("activeuser_backend", 'Created user');
55
        $this->stdout($info . PHP_EOL, Console::BOLD);
56
        $this->stdout(str_pad('', mb_strlen($info), '-') . PHP_EOL, Console::BOLD);
57
        $this->stdout(Yii::t('activeuser_general', 'Name') . ': ' . $nameString . PHP_EOL);
58
        $this->stdout(Yii::t('activeuser_general', 'Email') . ': ' . $emailString . PHP_EOL);
59
        $this->stdout(Yii::t('activeuser_general', 'Password') . ': ' . $passwordString . PHP_EOL);
60
    }
61
62
    /**
63
     * Block user
64
     * @param string $email user email to block
65
     */
66 View Code Duplication
    public function actionBlock($email = null)
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...
67
    {
68
        if (empty($email)) {
69
            $this->showUsage('email');
70
        }
71
        $user = $this->findUser($email);
72
        $nameString = $this->ansiFormat($user->name, Console::FG_GREEN);
73
        $emailString = $this->ansiFormat($user->email, Console::FG_GREEN);
74
        if (!$user->isActive()) {
75
            $this->showErrors([
76
                'error' => [
77
                    Yii::t('activeuser_backend', "Can't block user {name} with email {email}", [
78
                        'name' => $nameString,
79
                        'email' => $emailString,
80
                    ])
81
                ]
82
            ]);
83
        }
84
        $this->confirmAction(Yii::t("activeuser_backend", "Block user {name} with email {email}?", [
85
            'name' => $nameString,
86
            'email' => $emailString,
87
        ]));
88
        $user->block($this->sendEmail);
89
        $this->stdout(
90
            Yii::t('activeuser_backend', 'User {name} with email {email} was blocked', [
91
                'name' => $nameString,
92
                'email' => $emailString,
93
            ]) . PHP_EOL
94
        );
95
    }
96
97
    /**
98
     * Unblock user
99
     * @param string $email user email to unblock
100
     */
101 View Code Duplication
    public function actionUnblock($email = null)
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...
102
    {
103
        if (empty($email)) {
104
            $this->showUsage('email');
105
        }
106
        $user = $this->findUser($email);
107
        $nameString = $this->ansiFormat($user->name, Console::FG_GREEN);
108
        $emailString = $this->ansiFormat($user->email, Console::FG_GREEN);
109
        if (!$user->isBlocked()) {
110
            $this->showErrors([
111
                'error' => [
112
                    Yii::t('activeuser_backend', 'User {name} with email {email} not blocked', [
113
                        'name' => $nameString,
114
                        'email' => $emailString,
115
                    ])
116
                ]
117
            ]);
118
        }
119
        $this->confirmAction(Yii::t("activeuser_backend", 'Unblock user {name} with email {email}?', [
120
            'name' => $nameString,
121
            'email' => $emailString,
122
        ]));
123
        $user->unblock($this->sendEmail);
124
        $this->stdout(
125
            Yii::t('activeuser_backend', 'User {name} with email {email} was unblocked', [
126
                'name' => $nameString,
127
                'email' => $emailString,
128
            ]) . PHP_EOL
129
        );
130
    }
131
132
    /**
133
     * Change user password
134
     * @param string $email user email
135
     * @param string|null $password new password. If not set will be generated automatically
136
     */
137
    public function actionPassword($email = null, $password = null)
138
    {
139
        if (empty($email)) {
140
            $this->showUsage('email', 'password');
141
        }
142
        $user = $this->findUser($email);
143
        $nameString = $this->ansiFormat($user->name, Console::FG_GREEN);
144
        $emailString = $this->ansiFormat($user->email, Console::FG_GREEN);
145
        $this->confirmAction(Yii::t("activeuser_backend", 'Change password user {name} with email {email}?', [
146
            'name' => $nameString,
147
            'email' => $emailString,
148
        ]));
149
        $user->password = $password;
150
        $user->newPassword($this->sendEmail);
151
        $passwordString = $this->ansiFormat($user->password, Console::BOLD);
152
        $info = Yii::t("activeuser_backend", 'New user data');
153
        $this->stdout($info . PHP_EOL, Console::BOLD);
154
        $this->stdout(str_pad('', mb_strlen($info), '-') . PHP_EOL);
155
        $this->stdout(Yii::t('activeuser_general', 'Email') . ': ' . $emailString . PHP_EOL);
156
        $this->stdout(Yii::t('activeuser_general', 'Password') . ': ' . $passwordString . PHP_EOL);
157
    }
158
159
    /**
160
     * Find user
161
     * @param string $email user email for search
162
     * @return \inblank\activeuser\models\User
163
     * @throws \yii\base\ExitException
164
     * @throws \yii\base\InvalidConfigException
165
     */
166
    protected function findUser($email)
167
    {
168
        $user = Yii::createObject(self::di('User'))->findOne(['email' => $email]);
0 ignored issues
show
self::di('User') is of type *, but the function expects a callable.

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...
169
        if ($user !== null) {
170
            return $user;
171
        }
172
        return $this->showErrors([
173
            'user' => [
174
                Yii::t('activeuser_backend', 'User with email {email} not found', [
175
                    'email' => $this->ansiFormat($email, Console::BOLD)
176
                ]),
177
            ]
178
        ]);
179
    }
180
181
}
182