Issues (443)

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.

backend/controllers/SettingController.php (7 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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace backend\controllers;
9
10
use common\models\Option;
11
use common\models\search\Option as OptionSearch;
12
use Yii;
13
use yii\filters\AccessControl;
14
use yii\filters\VerbFilter;
15
use yii\web\Controller;
16
use yii\web\NotFoundHttpException;
17
18
/**
19
 * SettingController implements the CRUD actions for Option model.
20
 *
21
 * @author Agiel K. Saputra <[email protected]>
22
 * @since 0.1.0
23
 */
24
class SettingController extends Controller
25
{
26
    /**
27
     * @inheritdoc
28
     */
29
    public function behaviors()
30
    {
31
        return [
32
33
            'access' => [
34
                'class' => AccessControl::className(),
35
                'rules' => [
36
                    [
37
                        'actions' => ['index', 'create', 'view', 'update', 'delete'],
38
                        'allow' => true,
39
                        'roles' => ['superadmin'],
40
                    ],
41
                    [
42
                        'actions' => ['group'],
43
                        'allow' => true,
44
                        'roles' => ['administrator'],
45
                    ],
46
                ],
47
            ],
48
            'verbs' => [
49
                'class' => VerbFilter::className(),
50
                'actions' => [
51
                    'delete' => ['post'],
52
                ],
53
            ],
54
        ];
55
    }
56
57
    /**
58
     * Lists all Option models.
59
     *
60
     * @return mixed
61
     */
62 View Code Duplication
    public function actionIndex()
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...
63
    {
64
        $searchModel = new OptionSearch();
65
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
66
67
        return $this->render('index', [
68
            'searchModel' => $searchModel,
69
            'dataProvider' => $dataProvider,
70
        ]);
71
    }
72
73
    /**
74
     * Displays single Option model.
75
     *
76
     * @param integer $id
77
     * @return mixed
78
     */
79
    public function actionView($id)
80
    {
81
        return $this->render('view', [
82
            'model' => $this->findModel($id),
83
        ]);
84
    }
85
86
    /**
87
     * Creates a new Option model.
88
     * If creation is successful, the browser will be redirected to the 'view' page.
89
     *
90
     * @return mixed
91
     */
92 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...
93
    {
94
        $model = new Option();
95
96
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
97
            return $this->redirect(['view', 'id' => $model->id]);
98
        }
99
100
        return $this->render('create', [
101
            'model' => $model,
102
        ]);
103
    }
104
105
    /**
106
     * Updates an existing Option model.
107
     * If update is successful, the browser will be redirected to the 'view' page.
108
     *
109
     * @param integer $id
110
     * @return mixed
111
     */
112 View Code Duplication
    public function actionUpdate($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...
113
    {
114
        $model = $this->findModel($id);
115
116
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
0 ignored issues
show
The method load cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
The method save cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
117
            return $this->redirect(['view', 'id' => $model->id]);
118
        }
119
120
        return $this->render('update', [
121
            'model' => $model,
122
        ]);
123
    }
124
125
    /**
126
     * Deletes an existing Option model.
127
     * If deletion is successful, the browser will be redirected to the 'index' page.
128
     *
129
     * @param integer $id
130
     * @return mixed
131
     */
132
    public function actionDelete($id)
133
    {
134
        $this->findModel($id)->delete();
0 ignored issues
show
The method delete cannot be called on $this->findModel($id) (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
135
136
        return $this->redirect(['index']);
137
    }
138
139
140
    /**
141
     * Render option page for specific group of option.
142
     * It will use group file if exist.
143
     *
144
     * @param string $id
145
     * @return mixed
146
     */
147
    public function actionGroup($id)
148
    {
149
        $model = $this->findModelByGroup($id);
150
151
        if ($options = Yii::$app->request->post('Option')) {
152
            foreach ($options as $optionName => $option) {
153
                Option::up($optionName, $option['value']);
154
            }
155
            Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', 'Settings successfully saved.'));
0 ignored issues
show
The method getSession does only exist in yii\web\Application, but not in yii\console\Application.

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...
156
157
            return $this->redirect(['group', 'id' => $id]);
158
        }
159
160
        if (is_file($this->getViewPath() . '/' . strtolower($id) . '.php')) {
161
            return $this->render(strtolower($id), [
162
                'model' => (object)$model,
163
                'group' => $id,
164
            ]);
165
        }
166
167
        return $this->redirect(['index']);
168
    }
169
170
    /**
171
     * Finds the Option model based on its primary key value.
172
     * If the model is not found, a 404 HTTP exception will be thrown.
173
     *
174
     * @param integer $id
175
     * @return Option the loaded model
176
     * @throws NotFoundHttpException if the model cannot be found
177
     */
178
    protected function findModel($id)
179
    {
180
        if (($model = Option::findOne($id)) !== null) {
181
            return $model;
182
        }
183
184
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
185
    }
186
187
    /**
188
     * Finds the Option models based on their group.
189
     * If the models are not found, a 404 HTTP exception will be thrown.
190
     *
191
     * @param string $id
192
     * @return Option the loaded model
193
     * @throws NotFoundHttpException if the models cannot be found
194
     */
195
    protected function findModelByGroup($id)
196
    {
197
        if ($model = Option::find()->where(['group' => $id])->indexBy('name')->all()) {
198
            return $model;
199
        }
200
201
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
202
    }
203
}
204