Issues (1919)

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.

lib/Ajde/Query.php (4 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
class Ajde_Query extends Ajde_Object_Standard
4
{
5
    const ORDER_ASC = 'ASC';
6
    const ORDER_DESC = 'DESC';
7
8
    const OP_AND = 'AND';
9
    const OP_OR = 'OR';
10
11
    const JOIN_INNER = 'INNER';
12
    const JOIN_LEFT = 'LEFT';
13
14
    public $select = [];
15
    public $distinct = false;
16
    public $from = [];
17
    public $where = [];
18
    public $having = [];
19
    public $join = [];
20
    public $groupBy = [];
21
    public $orderBy = [];
22
    public $limit = ['start' => null, 'count' => null];
23
24
    public function reset()
25
    {
26
        $this->select = [];
27
        $this->from = [];
28
        $this->where = [];
29
        $this->having = [];
30
        $this->join = [];
31
        $this->groupBy = [];
32
        $this->orderBy = [];
33
        $this->limit = ['start' => null, 'count' => null];
34
    }
35
36
    public function addSelect($select)
37
    {
38
        $this->select[] = $select;
39
    }
40
41
    public function setDistinct($distinct)
42
    {
43
        $this->distinct = (bool) $distinct;
44
    }
45
46
    public function addFrom($from)
47
    {
48
        $this->from[] = $from;
49
    }
50
51
    public function addWhere($where, $operator = self::OP_AND)
52
    {
53
        $this->where[] = ['sql' => $where, 'operator' => $operator];
54
    }
55
56
    public function addHaving($having, $operator = self::OP_AND)
57
    {
58
        $this->having[] = ['sql' => $having, 'operator' => $operator];
59
    }
60
61
    public function addJoin($join, $type = self::JOIN_INNER)
62
    {
63
        $this->join[] = ['sql' => $join, 'type' => $type];
64
    }
65
66
    public function addOrderBy($field, $direction = self::ORDER_ASC)
67
    {
68
        $direction = strtoupper($direction);
69
        if (!in_array($direction, [self::ORDER_ASC, self::ORDER_DESC])) {
70
            // TODO:
71
            throw new Ajde_Exception('Collection ordering direction "'.$direction.'" not valid');
72
        }
73
        $this->orderBy[] = ['field' => $field, 'direction' => $direction];
74
    }
75
76
    public function addGroupBy($field)
77
    {
78
        $this->groupBy[] = $field;
79
    }
80
81
    public function limit($count, $start = 0)
82
    {
83
        $this->limit = ['count' => (int) $count, 'start' => (int) $start];
84
    }
85
86
    public function getSql()
87
    {
88
        $sql = '';
89
        $distinct = $this->distinct ? 'DISTINCT ' : '';
90
91
        // SELECT
92
        if (empty($this->select)) {
93
            $sql .= 'SELECT '.$distinct.'*';
94
        } else {
95
            $sql .= 'SELECT '.$distinct.implode(', ', $this->select);
96
        }
97
98
        // FROM
99 View Code Duplication
        if (empty($this->from)) {
0 ignored issues
show
This code seems to be duplicated across 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...
100
            // TODO:
101
            throw new Ajde_Exception('FROM clause can not be empty in query');
102
        } else {
103
            $sql .= ' FROM '.implode(', ', $this->from);
104
        }
105
106
        // JOIN
107
        if (!empty($this->join)) {
108
            foreach ($this->join as $join) {
109
                $sql .= ' '.$join['type'].' JOIN '.$join['sql'];
110
            }
111
        }
112
113
        // WHERE
114 View Code Duplication
        if (!empty($this->where)) {
0 ignored issues
show
This code seems to be duplicated across 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...
115
            $first = true;
116
            $sql .= ' WHERE';
117
            foreach ($this->where as $where) {
118
                if ($first === false) {
119
                    $sql .= ' '.$where['operator'];
120
                }
121
                $sql .= ' '.$where['sql'];
122
                $first = false;
123
            }
124
        }
125
126
        // GROUP BY
127 View Code Duplication
        if (!empty($this->groupBy)) {
0 ignored issues
show
This code seems to be duplicated across 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...
128
            $sql .= ' GROUP BY';
129
            $sql .= ' '.implode(', ', $this->groupBy);
130
        }
131
132
        // HAVING
133 View Code Duplication
        if (!empty($this->having)) {
0 ignored issues
show
This code seems to be duplicated across 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...
134
            $first = true;
135
            $sql .= ' HAVING';
136
            foreach ($this->having as $having) {
137
                if ($first === false) {
138
                    $sql .= ' '.$having['operator'];
139
                }
140
                $sql .= ' '.$having['sql'];
141
                $first = false;
142
            }
143
        }
144
145
        // ORDER BY
146
        if (!empty($this->orderBy)) {
147
            $sql .= ' ORDER BY';
148
            $orderBySql = [];
149
            foreach ($this->orderBy as $orderBy) {
150
                $orderBySql[] = $orderBy['field'].' '.$orderBy['direction'];
151
            }
152
            $sql .= ' '.implode(', ', $orderBySql);
153
        }
154
155
        // LIMIT
156
        if (isset($this->limit['count']) && !isset($this->limit['start'])) {
157
            $sql .= ' LIMIT '.$this->limit['count'];
158
        } elseif (isset($this->limit['count']) && isset($this->limit['start'])) {
159
            $sql .= ' LIMIT '.$this->limit['start'].', '.$this->limit['count'];
160
        }
161
162
        return $sql;
163
    }
164
}
165