Issues (2)

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/QueryBuilder.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
 * HiPanel API client made with HiART.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-hiart
6
 * @package   hipanel-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\hiart;
12
13
use hiqdev\hiart\Query;
14
use yii\base\NotSupportedException;
15
use yii\helpers\ArrayHelper;
16
use yii\helpers\Inflector;
17
18
/**
19
 * QueryBuilder for HiPanel API.
20
 */
21
class QueryBuilder extends \hiqdev\hiart\rest\QueryBuilder
22
{
23
    public function buildMethod(Query $query)
24
    {
25
        return 'POST';
26
    }
27
28
    public function buildUri(Query $query)
29
    {
30
        $action = $query->action;
31
        if (is_array($action)) {
32
            $from = reset($action);
33
        } else {
34
            if (ctype_upper($action[0])) {
35
                return $action;
36
            }
37
            $from = is_array($query->from) ? reset($query->from) : $query->from;
38
        }
39
        $from = Inflector::id2camel($from);
40
41
        return lcfirst($from . ($query->getOption('batch') ? 's' : '') . $this->buildCommand($query));
42
    }
43
44
    public function buildCommand(Query $query)
45
    {
46
        $action = $query->action;
47
        if (is_array($action)) {
48
            $action = end($action);
49
        }
50
51
        $prefix = '';
52
        if ($action === 'search' && empty($query->getOption('batch'))) {
53
            $prefix = 's';
54
        }
55
56
        if ($action === 'insert') {
57
            $action = 'create';
58
        }
59
60
        return $prefix . Inflector::id2camel($action);
61
    }
62
63
    public function buildFormParams(Query $query)
64
    {
65
        return $query->params;
66
    }
67
68
    public function buildAuth(Query $query)
69
    {
70
        $query->addParams($this->db->getAuth());
71
    }
72
73
    /**
74
     * @param Query $query
75
     * @throws NotSupportedException
76
     * @return Query
77
     */
78
    public function prepare(Query $query)
79
    {
80
        $parts = [];
81
        $query->prepare($this);
0 ignored issues
show
$this is of type this<hipanel\hiart\QueryBuilder>, but the function expects a object<yii\db\QueryBuilder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
83
        $this->buildSelect($query->select, $parts);
84
        $this->buildCount($query->count, $parts);
85
        $this->buildLimit($query->limit, $parts);
86
        $this->buildPage($query->offset, $query->limit, $parts);
87
        $this->buildOrderBy($query->orderBy, $parts);
88
89
        $parts = ArrayHelper::merge($parts, $this->buildCondition($query->where), $query->body);
90
91
        $query->addParams($parts);
92
93
        return $query;
94
    }
95
96
    public function buildCount($count, &$parts)
97
    {
98
        if (!empty($count)) {
99
            $parts['count'] = 1;
100
        }
101
    }
102
103
    public function buildLimit($limit, &$parts)
104
    {
105
        if (!empty($limit)) {
106
            if ($limit === -1) {
107
                $limit = 'ALL';
108
            }
109
            $parts['limit'] = $limit;
110
        }
111
    }
112
113
    public function buildPage($offset, $limit, &$parts)
114
    {
115
        if ($offset > 0) {
116
            $parts['page'] = ceil($offset / $limit) + 1;
117
        }
118
    }
119
120
    private $_sort = [
121
        SORT_ASC  => '_asc',
122
        SORT_DESC => '_desc',
123
    ];
124
125
    public function buildOrderBy($orderBy, &$parts)
126
    {
127
        if (!empty($orderBy)) {
128
            $parts['orderby'] = key($orderBy) . $this->_sort[reset($orderBy)];
129
        }
130
    }
131
132
    public function buildSelect($select, &$parts)
133
    {
134
        if (!empty($select)) {
135
            foreach ($select as $attribute) {
136
                $parts['select'][$attribute] = $attribute;
137
            }
138
        }
139
    }
140
}
141