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.

controllers/RuleController.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 yii2mod\rbac\controllers;
4
5
use Yii;
6
use yii\filters\VerbFilter;
7
use yii\web\Controller;
8
use yii\web\NotFoundHttpException;
9
use yii2mod\rbac\models\BizRuleModel;
10
use yii2mod\rbac\models\search\BizRuleSearch;
11
12
/**
13
 * Class RuleController
14
 *
15
 * @package yii2mod\rbac\controllers
16
 */
17
class RuleController extends Controller
18
{
19
    /**
20
     * @var string search class name for rules search
21
     */
22
    public $searchClass = [
23
        'class' => BizRuleSearch::class,
24
    ];
25
26
    /**
27
     * Returns a list of behaviors that this component should behave as.
28
     *
29
     * @return array
30
     */
31
    public function behaviors(): array
32
    {
33
        return [
34
            'verbs' => [
35
                'class' => VerbFilter::class,
36
                'actions' => [
37
                    'index' => ['get'],
38
                    'view' => ['get'],
39
                    'create' => ['get', 'post'],
40
                    'update' => ['get', 'post'],
41
                    'delete' => ['post'],
42
                ],
43
            ],
44
        ];
45
    }
46
47
    /**
48
     * List of all rules
49
     *
50
     * @return mixed
51
     */
52
    public function actionIndex()
53
    {
54
        $searchModel = Yii::createObject($this->searchClass);
55
        $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
56
57
        return $this->render('index', [
58
            'dataProvider' => $dataProvider,
59
            'searchModel' => $searchModel,
60
        ]);
61
    }
62
63
    /**
64
     * Displays a single Rule item.
65
     *
66
     * @param string $id
67
     *
68
     * @return mixed
69
     */
70
    public function actionView(string $id)
71
    {
72
        $model = $this->findModel($id);
73
74
        return $this->render('view', ['model' => $model]);
75
    }
76
77
    /**
78
     * Creates a new Rule item.
79
     *
80
     * If creation is successful, the browser will be redirected to the 'view' page.
81
     *
82
     * @return mixed
83
     */
84 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...
85
    {
86
        $model = new BizRuleModel();
87
88
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
89
            Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Rule has been saved.'));
90
91
            return $this->redirect(['view', 'id' => $model->name]);
92
        }
93
94
        return $this->render('create', ['model' => $model]);
95
    }
96
97
    /**
98
     * Updates an existing Rule item.
99
     *
100
     * If update is successful, the browser will be redirected to the 'view' page.
101
     *
102
     * @param string $id
103
     *
104
     * @return mixed
105
     */
106 View Code Duplication
    public function actionUpdate(string $id)
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...
107
    {
108
        $model = $this->findModel($id);
109
110
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
111
            Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Rule has been saved.'));
112
113
            return $this->redirect(['view', 'id' => $model->name]);
114
        }
115
116
        return $this->render('update', ['model' => $model]);
117
    }
118
119
    /**
120
     * Deletes an existing Rule item.
121
     *
122
     * If deletion is successful, the browser will be redirected to the 'index' page.
123
     *
124
     * @param string $id
125
     *
126
     * @return mixed
127
     */
128 View Code Duplication
    public function actionDelete(string $id)
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...
129
    {
130
        $model = $this->findModel($id);
131
        Yii::$app->authManager->remove($model->item);
0 ignored issues
show
The property item does not exist on object<yii2mod\rbac\models\BizRuleModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
132
        Yii::$app->session->setFlash('success', Yii::t('yii2mod.rbac', 'Rule has been deleted.'));
133
134
        return $this->redirect(['index']);
135
    }
136
137
    /**
138
     * Finds the BizRuleModel based on its primary key value.
139
     *
140
     * If the model is not found, a 404 HTTP exception will be thrown.
141
     *
142
     * @param string $id
143
     *
144
     * @return BizRuleModel the loaded model
145
     *
146
     * @throws \yii\web\NotFoundHttpException
147
     */
148
    protected function findModel(string $id)
149
    {
150
        $item = Yii::$app->authManager->getRule($id);
151
152
        if (!empty($item)) {
153
            return new BizRuleModel($item);
154
        }
155
156
        throw new NotFoundHttpException(Yii::t('yii2mod.rbac', 'The requested page does not exist.'));
157
    }
158
}
159