Issues (65)

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.

models/BizRuleModel.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 yii2mod\rbac\models;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\rbac\Rule;
8
9
/**
10
 * Class BizRuleModel
11
 *
12
 * @package yii2mod\rbac\models
13
 */
14
class BizRuleModel extends Model
15
{
16
    /**
17
     * @var string name of the rule
18
     */
19
    public $name;
20
21
    /**
22
     * @var int UNIX timestamp representing the rule creation time
23
     */
24
    public $createdAt;
25
26
    /**
27
     * @var int UNIX timestamp representing the rule updating time
28
     */
29
    public $updatedAt;
30
31
    /**
32
     * @var string Rule className
33
     */
34
    public $className;
35
36
    /**
37
     * @var \yii\rbac\ManagerInterface
38
     */
39
    protected $manager;
40
41
    /**
42
     * @var Rule
43
     */
44
    private $_item;
45
46
    /**
47
     * BizRuleModel constructor.
48
     *
49
     * @param \yii\rbac\Rule $item
50
     * @param array $config
51
     */
52
    public function __construct($item = null, $config = [])
53
    {
54
        $this->_item = $item;
55
        $this->manager = Yii::$app->authManager;
56
57
        if ($item !== null) {
58
            $this->name = $item->name;
59
            $this->className = get_class($item);
60
        }
61
62
        parent::__construct($config);
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function rules(): array
69
    {
70
        return [
71
            [['name', 'className'], 'trim'],
72
            [['name', 'className'], 'required'],
73
            ['className', 'string'],
74
            ['name', 'string', 'max' => 64],
75
            ['className', 'classExists'],
76
        ];
77
    }
78
79
    /**
80
     * Validate className
81
     */
82
    public function classExists()
83
    {
84
        if (!class_exists($this->className)) {
85
            $message = Yii::t('yii2mod.rbac', "Unknown class '{class}'", ['class' => $this->className]);
86
            $this->addError('className', $message);
87
88
            return;
89
        }
90
91
        if (!is_subclass_of($this->className, Rule::class)) {
92
            $message = Yii::t('yii2mod.rbac', "'{class}' must extend from 'yii\\rbac\\Rule' or its child class", [
93
                'class' => $this->className, ]);
94
            $this->addError('className', $message);
95
        }
96
    }
97
98
    /**
99
     * @inheritdoc
100
     */
101
    public function attributeLabels(): array
102
    {
103
        return [
104
            'name' => Yii::t('yii2mod.rbac', 'Name'),
105
            'className' => Yii::t('yii2mod.rbac', 'Class Name'),
106
        ];
107
    }
108
109
    /**
110
     * Check if record is new
111
     *
112
     * @return bool
113
     */
114
    public function getIsNewRecord(): bool
115
    {
116
        return $this->_item === null;
117
    }
118
119
    /**
120
     * Create object
121
     *
122
     * @param $id
123
     *
124
     * @return BizRuleModel|null
125
     */
126
    public static function find(int $id)
127
    {
128
        $item = Yii::$app->authManager->getRule($id);
129
130
        if ($item !== null) {
131
            return new static($item);
132
        }
133
134
        return null;
135
    }
136
137
    /**
138
     * Save rule
139
     *
140
     * @return bool
141
     */
142
    public function save(): bool
143
    {
144
        if ($this->validate()) {
145
            $class = $this->className;
146
            if ($this->_item === null) {
147
                $this->_item = new $class();
148
                $isNew = true;
149
                $oldName = false;
150
            } else {
151
                $isNew = false;
152
                $oldName = $this->_item->name;
153
            }
154
155
            $this->_item->name = $this->name;
156
157
            if ($isNew) {
158
                $this->manager->add($this->_item);
159
            } else {
160
                $this->manager->update($oldName, $this->_item);
0 ignored issues
show
It seems like $oldName defined by false on line 149 can also be of type false; however, yii\rbac\ManagerInterface::update() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
161
            }
162
163
            return true;
164
        }
165
166
        return false;
167
    }
168
169
    /**
170
     * @return null|Rule
171
     */
172
    public function getItem()
173
    {
174
        return $this->_item;
175
    }
176
}
177