Issues (9)

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.

src/VerifyAction.php (1 issue)

Labels
Severity

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
 * @link https://github.com/vuongxuongminh/yii2-mfa
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\mfa;
9
10
use Yii;
11
12
use yii\base\Action;
13
use yii\base\InvalidConfigException;
14
15
/**
16
 * Class VerifyAction provide an action verify mfa otp. For use, add it to actions method of your controller
17
 * Example:
18
 * ```php
19
 *       public function actions()
20
 *       {
21
 *           return [
22
 *               'verify' => [
23
 *                   'class' => 'vxm\mfa\VerifyAction',
24
 *                   'viewFile' => 'verify', // the name of view file use to render view
25
 *                   'formVar' => 'model', // the name of variable use to parse [[\vxm\mfa\OtpForm]] object to view file.
26
 *                   'retry' => true, // allow user retry when type wrong otp
27
 *                   'successCallback' => [$this, 'mfaPassed'], // callable call when user type valid otp if not set [[yii\web\Controller::goBack()]] will be call.
28
 *                   'invalidCallback' => [$this, 'mfaOtpInvalid'], // callable call when user type wrong otp if not set and property `retry` is false [[yii\web\User::loginRequired()]] will be call, it should be use for set flash notice to user.
29
 *                   'retry' => true, // allow user retry when type wrong otp
30
 *               ]
31
 *           ];
32
 *       }
33
 * ```
34
 *
35
 * @author Vuong Minh <[email protected]>
36
 * @since 1.0.0
37
 */
38
class VerifyAction extends Action
39
{
40
41
    use EnsureUserBehaviorAttachedTrait;
42
43
    /**
44
     * @var string the name of view file if not set an id of this action will be use.
45
     */
46
    public $viewFile;
47
48
    /**
49
     * @var string the name of variable in view refer to an object of `vxm\mfa\OtpForm`.
50
     */
51
    public $formVar = 'model';
52
53
    /**
54
     * @var callable|null when an identity had been verified it will be call. If not set, [[\yii\web\Controller::goBack()]] will be call.
55
     * This action will be parse at first param and `vxm\mfa\OtpForm` is second param
56
     * Example:
57
     *
58
     * ```php
59
     * 'successCallback' => function(\vxm\mfa\VerifyAction $action, \vxm\mfa\OtpForm $otp) {
60
     *
61
     *      return $action->controller->redirect(['site/dash-board']);
62
     * }
63
     *
64
     * ```
65
     */
66
    public $successCallback;
67
68
    /**
69
     * @var callable|null when an user submit wrong otp it will be call, if not set, [[yii\web\User::loginRequired()]] will be call.
70
     * This action will be parse at first param and `vxm\mfa\OtpForm` is second param
71
     * Example:
72
     *
73
     * ```php
74
     * 'invalidCallback' => function(\vxm\mfa\VerifyAction $action, \vxm\mfa\OtpForm $otp) {
75
     *      Yii::$app->session->setFlash('Otp is not valid');
76
     *
77
     *      return $action->controller->redirect(['site/login']);
78
     * }
79
     *
80
     * ```
81
     */
82
    public $invalidCallback;
83
84
    /**
85
     * @var bool weather allow user can retry when type wrong or not.
86
     */
87
    public $retry = false;
88
89
    /**
90
     * @var string the form class handle end-user data
91
     */
92
    public $formClass = OtpForm::class;
93
94
    /**
95
     * @inheritDoc
96
     * @throws InvalidConfigException
97
     */
98 4
    public function init()
99
    {
100 4
        $this->ensureUserBehaviorAttached();
101 4
        $this->viewFile = $this->viewFile ?? $this->id;
102
103 4
        parent::init();
104 4
    }
105
106
    /**
107
     * @inheritDoc
108
     */
109 4
    public function beforeRun()
110
    {
111 4
        $data = $this->user->getIdentityLoggedIn();
112
113 4
        if ($data === null) {
114 1
            $this->user->loginRequired();
115
116 1
            return false;
117
        }
118
119 3
        return parent::beforeRun();
120
    }
121
122
    /**
123
     * @return mixed|string|\yii\web\Response
124
     * @throws \yii\web\ForbiddenHttpException
125
     */
126 3
    public function run()
127
    {
128 3
        $formClass = $this->formClass;
129 3
        $form = new $formClass(['user' => $this->user]);
130
131 3
        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
132 2
            if ($form->verify()) {
133 1
                $this->user->switchIdentityLoggedIn();
134 1
                $this->user->removeIdentityLoggedIn();
135
136 1
                if ($this->successCallback) {
137
                    return call_user_func($this->successCallback, $this, $form);
138
                } else {
139 1
                    return $this->controller->goBack();
0 ignored issues
show
The method goBack does only exist in yii\web\Controller, but not in yii\base\Controller and yii\console\Controller.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
140
                }
141
            } else {
142 1
                if (!$this->retry) {
143 1
                    $this->user->removeIdentityLoggedIn();
144
                }
145
146 1
                if ($this->invalidCallback) {
147
                    return call_user_func($this->invalidCallback, $this, $form);
148 1
                } elseif (!$this->retry) {
149 1
                    return $this->user->loginRequired();
150
                }
151
            }
152
        }
153
154 2
        return $this->controller->render($this->viewFile, [$this->formVar => $form]);
155
    }
156
157
}
158