Issues (434)

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/actions/BillManagementAction.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
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\actions;
12
13
use hipanel\modules\finance\forms\BillForm;
14
use hipanel\modules\finance\models\Bill;
15
use hipanel\modules\finance\providers\BillTypesProvider;
16
use hiqdev\hiart\Collection;
17
use hiqdev\hiart\ResponseErrorException;
18
use Yii;
19
use yii\base\Action;
20
use yii\web\Controller;
21
use yii\web\Response;
22
23
class BillManagementAction extends Action
24
{
25
    /**
26
     * @var \yii\web\Request
27
     */
28
    protected $request;
29
30
    /**
31
     * @var Collection
32
     */
33
    protected $collection;
34
    /**
35
     * @var BillTypesProvider
36
     */
37
    private $billTypesProvider;
38
39
    /**
40
     * @var string
41
     */
42
    public $scenario;
43
44
    /**
45
     * @var string The view that represents current update action
46
     */
47
    public $_view;
48
49
    /**
50
     * @var bool
51
     */
52
    public $forceNewRecord = false;
53
54
    public function __construct($id, Controller $controller, BillTypesProvider $billTypesProvider, array $config = [])
55
    {
56
        parent::__construct($id, $controller, $config);
57
58
        $this->request = Yii::$app->request;
59
        $this->billTypesProvider = $billTypesProvider;
60
    }
61
62
    public function init()
63
    {
64
        parent::init();
65
66
        if (!isset($this->scenario) || !in_array($this->scenario, [BillForm::SCENARIO_CREATE, BillForm::SCENARIO_UPDATE, BillForm::SCENARIO_COPY], true)) {
67
            $this->scenario = $this->id;
68
        }
69
    }
70
71
    public function run()
72
    {
73
        $this->createCollection();
74
        $this->findBills();
75
76
        $result = $this->saveBills();
77
        if ($result instanceof Response) {
78
            return $result;
79
        }
80
81
        list($billTypes, $billGroupLabels) = $this->billTypesProvider->getGroupedList();
82
83
        return $this->controller->render($this->view, [
84
            'models' => $this->collection->getModels(),
85
            'billTypes' => $billTypes,
86
            'billGroupLabels' => $billGroupLabels,
87
        ]);
88
    }
89
90
    private function findBills()
91
    {
92
        $ids = $this->getRequestedIds();
93
94
        if ($ids === false) {
95
            return;
96
        }
97
98
        $bills = Bill::find()->joinWith('charges')->where(['ids' => $ids, 'with_charges' => true])->all();
99
        $billForms = BillForm::createMultipleFromBills($bills, $this->scenario);
100
        if ($this->forceNewRecord === true) {
101
            foreach ($billForms as $model) {
102
                $model->forceNewRecord();
103
            }
104
        }
105
        $this->collection->set($billForms);
106
    }
107
108
    private function getRequestedIds()
109
    {
110
        $request = $this->request;
111
112
        if ($request->isPost && ($ids = $request->post('selection')) !== null) {
113
            return $ids;
114
        }
115
116
        if ($request->isGet && ($id = $request->get('id')) !== null) {
117
            return [$id];
118
        }
119
120
        if ($request->isPost && $request->post('BillForm') !== null) {
121
            return false;
122
        }
123
124
        if ($this->scenario === BillForm::SCENARIO_CREATE) {
125
            $this->collection->set([new BillForm(['scenario' => $this->scenario])]);
126
127
            return true;
128
        }
129
130
        throw new \yii\web\UnprocessableEntityHttpException('Id is missing');
131
    }
132
133
    private function createCollection()
134
    {
135
        $this->collection = new Collection([
136
            'model' => new BillForm(['scenario' => $this->scenario]),
137
            'scenario' => $this->scenario,
138
            'loadFormatter' => function ($baseModel, $key, $value) {
139
                /** @var BillForm $baseModel */
140
                $charges = $this->request->post($baseModel->newCharge()->formName());
141
                $value['charges'] = isset($charges[$key]) ? $charges[$key] : [];
142
143
                return [$key, $value];
144
            },
145
            'dataCollector' => function ($model) {
146
                /** @var BillForm $model */
147
                return [$model->getPrimaryKey(), $model->toArray()];
148
            },
149
        ]);
150
    }
151
152
    private function saveBills()
153
    {
154
        $request = $this->request;
155
        $collection = $this->collection;
156
157
        if (
158
            $request->isPost
159
            && ($payload = $request->post($this->collection->formName)) !== null
160
            && $collection->load($payload)
161
            && $collection->validate()
162
        ) {
163
            try {
164
                $collection->save();
165
                $this->addSuccessFlash();
166
167
                return $this->controller->redirect(['@bill', 'id_in' => $collection->getIds()]);
0 ignored issues
show
The method redirect 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...
168
            } catch (ResponseErrorException $e) {
169
                Yii::$app->session->addFlash('error', $e->getMessage());
170
171
                return false;
172
            }
173
        }
174
175
        return null;
176
    }
177
178
    private function addSuccessFlash()
179
    {
180 View Code Duplication
        if ($this->scenario === BillForm::SCENARIO_CREATE) {
181
            return Yii::$app->session->addFlash('success', Yii::t('hipanel:finance', 'Bill was created successfully'));
182
        }
183
184 View Code Duplication
        if ($this->scenario === BillForm::SCENARIO_UPDATE) {
185
            return Yii::$app->session->addFlash('success', Yii::t('hipanel:finance', 'Bill was updated successfully'));
186
        }
187
    }
188
189
    /**
190
     * @return string
191
     */
192
    public function getView()
193
    {
194
        return $this->_view ?: $this->scenario;
195
    }
196
197
    /**
198
     * @param string $view
199
     */
200
    public function setView($view)
201
    {
202
        $this->_view = $view;
203
    }
204
}
205