Issues (319)

Security Analysis    no request data  

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/Controller/DataController.php (9 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
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid\Controller;
8
9
use Nnx\DataGrid\Adapter\DoctrineDBAL;
10
use Nnx\DataGrid\Condition\Conditions;
11
use Zend\Mvc\Controller\AbstractActionController;
12
use Nnx\DataGrid\GridInterface;
13
use Nnx\DataGrid\Condition\SimpleCondition;
14
use Zend\View\Model\ViewModel;
15
16
/**
17
 * Class DataController
18
 * @package Nnx\DataGrid\Controller
19
 */
20
class DataController extends AbstractActionController
21
{
22
    /**
23
     * Возвращает данные для таблиц
24
     * @return ViewModel
25
     * @throws Exception\InvalidConditionNameException
26
     * @throws Exception\InvalidConditionValueException
27
     * @throws Exception\InvalidGridNameException
28
     */
29
    public function getAction()
30
    {
31
        /** @var \ZF\ContentNegotiation\Request $request */
32
        $request = $this->getRequest();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
        $gridName = $request->getQuery('grid');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
        $limit = (int)$request->getQuery('limit', 25);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
        $offset = (int)$request->getQuery('offset', 0);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
        $orderField = $request->getQuery('sidx', null);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
37
        $orderType = $request->getQuery('sorder', null);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
        $collapsedRows = is_array($request->getPost('collapsedRows')) ? $request->getPost('collapsedRows') : [];
39
        /**
40
         * $conditions => [
41
         *      [
42
         *          'key' => $name,
43
         *          'value' => $value
44
         *      ]
45
         * ];
46
         */
47
        $conditions = $request->getQuery('conditions', []);
48
        if (!$gridName) {
49
            throw new Exception\InvalidGridNameException('Не задано имя таблицы для получения данных');
50
        }
51
        /** @var GridInterface $grid */
52
        $grid = $this->getServiceLocator()->get('GridManager')->get('grids.' . $gridName);
53
54
        $adapter = $grid->getAdapter();
55
        if ($adapter instanceof DoctrineDBAL) {
56
            $adapter->setLimit($limit);
57
            $adapter->setOffset($offset);
58
            if ($orderField && $orderType) {
59
                $adapter->setOrder([
60
                    [
61
                        'field' => $orderField,
62
                        'order' => $orderType
63
                    ]
64
                ]);
65
            }
66
        }
67
68
        $conditionsObj = new Conditions();
69
        foreach ($conditions as $cond) {
0 ignored issues
show
The expression $conditions of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
70
            if (is_array($cond)) {
71
                $condition = $this->getCondition($cond);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
72
                $conditionsObj[] = $condition;
73
            }
74
        }
75
        $grid->setConditions($conditionsObj);
76
        $result = new ViewModel(['grid' => $grid, 'collapsedRows' => $collapsedRows]);
77
        $result->setTerminal(true);
78
        return $result;
79
    }
80
81
    /**
82
     * @param array $conditionData
83
     * @return SimpleCondition
84
     * @throws Exception\InvalidConditionNameException
85
     * @throws Exception\InvalidConditionValueException
86
     */
87
    protected function getCondition(array $conditionData)
88
    {
89
        if (!array_key_exists('key', $conditionData) || !$conditionData['key']) {
90
            throw new Exception\InvalidConditionNameException('Не задано имя условия для выборки');
91
        }
92
93
        if (!array_key_exists('value', $conditionData)) {
94
            throw new Exception\InvalidConditionValueException('Не передано значение для условия выборки.');
95
        }
96
97
        $conditionType = SimpleCondition::CRITERIA_TYPE_EQUAL;
98
        return new SimpleCondition($conditionData['key'], $conditionType, $conditionData['value']);
99
    }
100
}
0 ignored issues
show
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
101