Issues (6)

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.

library/Nestedset/Model/Builder.php (2 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 Nestedset_Model_Builder
4
{
5
    /**
6
     * Add an element to the end of the tree.
7
     *
8
     * @param $model|NestedSet_Model    Nested set model
9
     * @param $name|string              Name of the element
10
     * @param $reference|int            Id of the reference element
11
     *
12
     * @return $this
13
     */
14
    public function append(NestedSet_Model $nestedset, $name)
15
    {
16
        $db = $nestedset->getDb();
17
18
        $select = $db->select();
19
        $select->from($nestedset->getTableName(), array('max' => "MAX({$nestedset->getStructureRight()})"));
20
21
        $stmt   = $db->query($select);
22
        $result = $stmt->fetch();
23
24
        if (false === $result) {
25
            $result = 0;
26
        } else {
27
            $result = $result['max'];
28
        }
29
30
        $left  = $result + 1;
31
        $right = $result + 2;
32
33
        try {
34
            $db->beginTransaction();
35
36
            // insert at the end of the nest
37
            $values = array(
38
                $nestedset->getStructureName() => $name,
39
                $nestedset->getStructureLeft() => $left,
40
                $nestedset->getStructureRight() => $right,
41
            );
42
43
            $db->insert($nestedset->getTableName(), $values);
44
            $db->commit();
45
        } catch (Exception $e) {
46
            $db->rollBack();
47
            throw $e;
48
        }
49
50
        return $this;
51
    }
52
53
    /**
54
     * Add an element into another as its child.
55
     *
56
     * @param $model|NestedSet_Model    Nested set model
57
     * @param $name|string              Name of the element
58
     * @param $reference|int            Id of the reference element
59
     *
60
     * @return $this
61
     */
62
    public function addInto(NestedSet_Model $nestedset, $name, $reference)
63
    {
64
        $db = $nestedset->getDb();
65
66
        // get parent's right value
67
        $select = $db->select();
68
        $select->from($nestedset->getTableName(), $nestedset->getStructureRight());
69
        $select->where("{$nestedset->getStructureId()} = $reference");
70
71
        $stmt   = $db->query($select);
72
        $result = $stmt->fetch();
73
74
        $right = $result[$nestedset->getStructureRight()];
75
76
        try {
77
            $db->beginTransaction();
78
79
            // move next elements' right to make room
80
            $db->query("
81
                UPDATE {$nestedset->getTableName()}
82
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} + 2
83
                 WHERE {$nestedset->getStructureRight()} > $right;
84
            ");
85
86
            // move next elements' left
87
            $db->query("
88
                UPDATE {$nestedset->getTableName()}
89
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} + 2
90
                 WHERE {$nestedset->getStructureLeft()} > $right;
91
            ");
92
93
            // make room into parent element
94
            $db->query("
95
                UPDATE {$nestedset->getTableName()}
96
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} + 2
97
                 WHERE {$nestedset->getStructureId()} = :reference;
98
            ", array(
99
                'reference' => $reference,
100
            ));
101
102
            // insert new element
103
            $values = array(
104
                $nestedset->getStructureName() => $name,
105
                $nestedset->getStructureLeft() => $right,
106
                $nestedset->getStructureRight() => $right + 1,
107
            );
108
109
            $db->insert($nestedset->getTableName(), $values);
110
            $db->commit();
111
        } catch (Exception $e) {
112
            $db->rollBack();
113
            throw $e;
114
        }
115
116
        return $this;
117
    }
118
119
    /**
120
     * Move an element into another as its child.
121
     *
122
     * @param $model|NestedSet_Model    Nested set model
123
     * @param $element|array            Element to move
124
     * @param $reference|array          Reference element to move into
125
     *
126
     * @return $this
127
     */
128
    public function moveInto(NestedSet_Model $nestedset, array $element, array $reference)
129
    {
130
        $db = $nestedset->getDb();
131
132
        try {
133
            // Check it can be moved into. XXX change when we'll get one level
134
            if ($element[0][$nestedset->getStructureLeft()] > $reference[0][$nestedset->getStructureLeft()] &&
135
                $element[0][$nestedset->getStructureLeft()] < $reference[0][$nestedset->getStructureRight()]) {
136
                // already into
137
                return false;
138
            }
139
140
            $db->beginTransaction();
141
            // first make room into reference
142
            // @TODO make a protected method to make room
143
            // with must always be a pair number
144
            $elementWidth = $nestedset->getNodeWidth($element[0][$nestedset->getStructureId()]);
145
146
            // move right
147
            $referenceRight = $reference[0][$nestedset->getStructureRight()];
148
            $db->query("
149
                UPDATE {$nestedset->getTableName()}
150
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} + $elementWidth
151
                 WHERE {$nestedset->getStructureRight()} >= $referenceRight;
152
            ");
153
154
            // move left
155
            $db->query("
156
                UPDATE {$nestedset->getTableName()}
157
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} + $elementWidth
158
                 WHERE {$nestedset->getStructureLeft()} > $referenceRight;
159
            ");
160
161
            // then move element (and it's children)
162
            $element    = $nestedset->getElement($element[0][$nestedset->getStructureId()]);
163
            $elementIds = array();
164
            foreach ($element as $one) {
165
                array_push($elementIds, $one[$nestedset->getStructureId()]);
166
            }
167
            $elementIds = implode(', ', $elementIds);
168
169
            $difference = $reference[0][$nestedset->getStructureRight()] - $element[0][$nestedset->getStructureLeft()];
170
171
            $db->query("
172
                UPDATE {$nestedset->getTableName()}
173
                   SET {$nestedset->getStructureLeft()}  = {$nestedset->getStructureLeft()}  + $difference,
174
                       {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} + $difference
175
                 WHERE {$nestedset->getStructureId()} IN ($elementIds);
176
            ");
177
178
            // move what was on the right of the element
179
            $db->query("
180
                UPDATE {$nestedset->getTableName()}
181
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} - $elementWidth
182
                 WHERE {$nestedset->getStructureLeft()} > {$element[0][$nestedset->getStructureLeft()]};
183
            ");
184
185
            $db->query("
186
                UPDATE {$nestedset->getTableName()}
187
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} - $elementWidth
188
                 WHERE {$nestedset->getStructureRight()} > {$element[0][$nestedset->getStructureRight()]};
189
            ");
190
191
            $db->commit();
192
        } catch (Exception $e) {
193
            $db->rollBack();
194
            throw $e;
195
        }
196
    }
197
198
    /**
199
     * Recursively delete a node, with all its children
200
     *
201
     * @param $model|NestedSet_Model    Nested set model
202
     * @param $tree|array
203
     *
204
     * @return $this
205
     */
206
    public function deleteRecursive(NestedSet_Model $nestedset, array $tree)
207
    {
208
        $db = $nestedset->getDb();
209
210
        // get interval for recursive delete
211
        $left  = (int) $tree[$nestedset->getStructureLeft()];
212
        $right = (int) $tree[$nestedset->getStructureRight()];
213
214
        try {
215
            $db->beginTransaction();
216
217
            $delete = $db->delete($nestedset->getTableName(), "{$nestedset->getStructureLeft()} BETWEEN $left AND $right");
0 ignored issues
show
$delete is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
218
219
            // update other elements
220
            $width = $right - $left + 1;
221
222
            // update right
223
            $db->query("
224
                UPDATE {$nestedset->getTableName()}
225
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} - $width
226
                 WHERE {$nestedset->getStructureRight()} > $right
227
            ");
228
229
            // update left
230
            $db->query("
231
                UPDATE {$nestedset->getTableName()}
232
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} - $width
233
                 WHERE {$nestedset->getStructureLeft()} > $right
234
            ");
235
236
            $db->commit();
237
        } catch (Exception $e) {
238
            $db->rollBack();
239
            throw $e;
240
        }
241
242
        return $this;
243
    }
244
245
    /**
246
     * Delete a node, but move all its children outside first
247
     *
248
     * @param $model|NestedSet_Model    Nested set model
249
     * @param $tree|array
250
     *
251
     * @return $this
252
     */
253
    public function deleteNonRecursive(NestedSet_Model $nestedset, array $tree)
254
    {
255
        $db = $nestedset->getDb();
256
257
        $left = (int) $tree[$nestedset->getStructureLeft()];
258
        $right = (int) $tree[$nestedset->getStructureRight()];
259
260
        try {
261
            $db->beginTransaction();
262
263
            $delete = $db->delete($nestedset->getTableName(), "{$nestedset->getStructureId()} = {$tree[$nestedset->getStructureId()]}");
0 ignored issues
show
$delete is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
264
265
            // update other elements
266
            $width = 2;
267
268
            // update right for inner elements
269
            $db->query("
270
                UPDATE {$nestedset->getTableName()}
271
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} - 1
272
                 WHERE {$nestedset->getStructureLeft()} > $left AND {$nestedset->getStructureRight()} < $right
273
            ");
274
275
            // update left for inner elements
276
            $db->query("
277
                UPDATE {$nestedset->getTableName()}
278
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} - 1
279
                 WHERE {$nestedset->getStructureLeft()} > $left AND {$nestedset->getStructureRight()} < $right
280
            ");
281
282
            // update right for outer elements
283
            $db->query("
284
                UPDATE {$nestedset->getTableName()}
285
                   SET {$nestedset->getStructureRight()} = {$nestedset->getStructureRight()} - $width
286
                 WHERE {$nestedset->getStructureRight()} > $right
287
            ");
288
289
            // update left for outer elements
290
            $db->query("
291
                UPDATE {$nestedset->getTableName()}
292
                   SET {$nestedset->getStructureLeft()} = {$nestedset->getStructureLeft()} - $width
293
                 WHERE {$nestedset->getStructureLeft()} > $left AND {$nestedset->getStructureRight()} >= $right
294
            ");
295
296
            $db->commit();
297
        } catch (Exception $e) {
298
            $db->rollBack();
299
            throw $e;
300
        }
301
302
        return $this;
303
    }
304
}
305