Issues (229)

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/IndexAction.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
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\actions;
12
13
use hipanel\base\FilterStorage;
14
use hipanel\grid\RepresentationCollectionFinder;
15
use hipanel\widgets\SynchronousCountEnabler;
16
use hiqdev\higrid\representations\RepresentationCollection;
17
use hiqdev\higrid\representations\RepresentationCollectionInterface;
18
use Yii;
19
use yii\grid\GridView;
20
use yii\helpers\ArrayHelper;
21
use yii\helpers\Inflector;
22
use yii\web\Controller;
23
24
/**
25
 * Class IndexAction.
26
 */
27
class IndexAction extends SearchAction
28
{
29
    public const VARIANT_PAGER_RESPONSE = 'pager';
30
31
    public const VARIANT_SUMMARY_RESPONSE = 'summary';
32
33
    /**
34
     * @var string view to render
35
     */
36
    protected $_view;
37
38
    /**
39
     * GET AJAX answer options for `VariantAction`, for example:
40
     * ```
41
     *      [
42
     *          'headerValue1' => fn(VariantAction $action): string => 'response1',
43
     *          'headerValue2' => fn(VariantAction $action): string => 'response2',
44
     *      ],
45
     * ```
46
     * @var array
47
     */
48
    public array $responseVariants = [];
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
49
50
    /**
51
     * @var RepresentationCollectionFinder
52
     */
53
    private $representationCollectionFinder;
54
55
    public function setView($value)
56
    {
57
        $this->_view = $value;
58
    }
59
60
    public function getView()
61
    {
62
        if ($this->_view === null) {
63
            $this->_view = lcfirst(Inflector::id2camel($this->id));
64
        }
65
66
        return $this->_view;
67
    }
68
69
    public function __construct(string $id, Controller $controller, RepresentationCollectionFinder $representationCollectionFinder, array $config = [])
70
    {
71
        parent::__construct($id, $controller, $config);
72
        $this->representationCollectionFinder = $representationCollectionFinder;
73
    }
74
75
    /**
76
     * @var array The map of filters for the [[hipanel\base\FilterStorage|FilterStorage]]
77
     */
78
    public $filterStorageMap = [];
79
80
    protected function getDefaultRules()
81
    {
82
        return ArrayHelper::merge([
83
            'html | pjax' => [
84
                'save' => false,
85
                'flash' => false,
86
                'success' => [
87
                    'class' => RenderAction::class,
88
                    'view' => $this->getView(),
89
                    'data' => $this->data,
90
                    'params' => function () {
91
                        return [
92
                            'model' => $this->getSearchModel(),
93
                            'dataProvider' => $this->getDataProvider(),
94
                            'representationCollection' => $this->ensureRepresentationCollection(),
95
                            'uiModel' => $this->getUiModel(),
96
                        ];
97
                    },
98
                ],
99
            ],
100
            'GET ajax' => [
101
                'class' => VariantsAction::class,
102
                'variants' => array_merge([
103
                    self::VARIANT_PAGER_RESPONSE => fn(VariantsAction $action): string => SynchronousCountEnabler::widget([
104
                        'dataProvider' => $action->parent->getDataProvider(),
105
                        'content' => fn(GridView $grid): string => $grid->renderPager(),
106
                    ]),
107
                    self::VARIANT_SUMMARY_RESPONSE => fn(VariantsAction $action): string => SynchronousCountEnabler::widget([
108
                        'dataProvider' => $action->parent->getDataProvider(),
109
                        'content' => fn(GridView $grid): string => $grid->renderSummary(),
110
                    ]),
111
                ], $this->responseVariants),
112
            ],
113
        ], parent::getDefaultRules());
114
    }
115
116
    public function getUiModel()
117
    {
118
        return $this->controller->indexPageUiOptionsModel;
119
    }
120
121
    /**
122
     * Method tries to guess representation collection class name and create object
123
     * Creates empty collection when no specific representation exists.
124
     *
125
     * @return RepresentationCollection|RepresentationCollectionInterface
126
     */
127
    protected function ensureRepresentationCollection()
128
    {
129
        return $this->representationCollectionFinder->findOrFallback();
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function getDataProvider()
136
    {
137
        if ($this->dataProvider === null) {
138
            $request = Yii::$app->request;
139
140
            $formName = $this->getSearchModel()->formName();
141
            $requestFilters = $request->get($formName) ?: $request->get() ?: $request->post();
142
143
            // Don't save filters for ajax requests, because
144
            // the request is probably triggered with select2 or smt similar
145
            if ($request->getIsPjax() || !$request->getIsAjax()) {
146
                $filterStorage = new FilterStorage(['map' => $this->filterStorageMap]);
147
148
                if ($request->getIsPost() && $request->post('clear-filters')) {
149
                    $filterStorage->clearFilters();
150
                }
151
152
                $filterStorage->set($requestFilters);
153
154
                // Apply filters from storage only when request does not contain any data
155
                if (empty($requestFilters)) {
156
                    $requestFilters = $filterStorage->get();
157
                }
158
            }
159
160
            $search = ArrayHelper::merge($this->findOptions, $requestFilters);
161
162
            $this->returnOptions[$this->controller->modelClassName()] = ArrayHelper::merge(
163
                ArrayHelper::remove($search, 'return', []),
164
                ArrayHelper::remove($search, 'rename', [])
165
            );
166
167
            if ($formName !== '') {
168
                $search = [$formName => $search];
169
            }
170
            $this->dataProvider = $this->getSearchModel()->search($search, $this->dataProviderOptions);
171
172
            // Set sort
173
            if ($this->getUiModel()->sort) {
174
                $this->dataProvider->setSort(['defaultOrder' => [$this->getUiModel()->sortAttribute => $this->getUiModel()->sortDirection]]);
175
            }
176
177
            // Set pageSize
178
            if ($this->getUiModel()->per_page) {
179
                $this->dataProvider->setPagination(['pageSize' => $this->getUiModel()->per_page]);
180
            }
181
        }
182
183
        return $this->dataProvider;
184
    }
185
}
186