Issues (194)

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/SQLParser/PHPSQLParserUtils.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
/**
4
 * parser-utils.php.
5
 *
6
 * These are utility functions for the PHPSQLParser.
7
 *
8
 * Copyright (c) 2010-2012, Justin Swanhart
9
 * with contributions by André Rothe <[email protected], [email protected]>
10
 *
11
 * All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without modification,
14
 * are permitted provided that the following conditions are met:
15
 *
16
 *   * Redistributions of source code must retain the above copyright notice,
17
 *     this list of conditions and the following disclaimer.
18
 *   * Redistributions in binary form must reproduce the above copyright notice,
19
 *     this list of conditions and the following disclaimer in the documentation
20
 *     and/or other materials provided with the distribution.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25
 * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31
 * DAMAGE.
32
 */
33
namespace SQLParser;
34
35
/**
36
 * This class implements some helper functions.
37
 *
38
 * @author arothe
39
 */
40
class PHPSQLParserUtils extends PHPSQLParserConstants
41
{
42
    /**
43
     * Prints an array only if debug mode is on.
44
     *
45
     * @param array $s
0 ignored issues
show
There is no parameter named $s. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
     * @param bool  $return, if true, the formatted array is returned via return parameter
0 ignored issues
show
There is no parameter named $return,. Did you maybe mean $return?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
47
     */
48
    protected function preprint($arr, $return = false)
0 ignored issues
show
preprint uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
49
    {
50
        $x = '<pre>';
51
        $x .= print_r($arr, 1);
52
        $x .= '</pre>';
53
        if ($return) {
54
            return $x;
55
        } else {
56
            if (isset($_ENV['DEBUG'])) {
57
                print $x."\n";
58
            }
59
        }
60
    }
61
62
    /**
63
     * Ends the given string $haystack with the string $needle?
64
     *
65
     * @param string $haystack
66
     * @param string $needle
67
     */
68 View Code Duplication
    protected function endsWith($haystack, $needle)
0 ignored issues
show
This method seems to be duplicated in 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...
69
    {
70
        $length = strlen($needle);
71
        if ($length == 0) {
72
            return true;
73
        }
74
75
        $start = $length * -1;
76
77
        return (substr($haystack, $start) === $needle);
78
    }
79
80
    /**
81
     * Revokes the escaping characters from an expression.
82
     */
83
    protected function revokeEscaping($sql)
84
    {
85
        $result = trim($sql);
86
        if (($result[0] === '`') && ($result[strlen($result) - 1] === '`')) {
87
            $result = substr($result, 1, -1);
88
        }
89
90
        return str_replace('``', '`', $result);
91
    }
92
93
    /**
94
     * This method removes parenthesis from start of the given string.
95
     * It removes also the associated closing parenthesis.
96
     */
97
    protected function removeParenthesisFromStart($token)
98
    {
99
        $parenthesisRemoved = 0;
100
101
        $trim = trim($token);
102
        if ($trim !== '' && $trim[0] === '(') { // remove only one parenthesis pair now!
103
            ++$parenthesisRemoved;
104
            $trim[0] = ' ';
105
            $trim = trim($trim);
106
        }
107
108
        $parenthesis = $parenthesisRemoved;
109
        $i = 0;
110
        $string = 0;
111
        while ($i < strlen($trim)) {
112
            if ($trim[$i] === '\\') {
113
                $i += 2; # an escape character, the next character is irrelevant
114
                continue;
115
            }
116
117
            if ($trim[$i] === "'" || $trim[$i] === '"') {
118
                ++$string;
119
            }
120
121
            if (($string % 2 === 0) && ($trim[$i] === '(')) {
122
                ++$parenthesis;
123
            }
124
125
            if (($string % 2 === 0) && ($trim[$i] === ')')) {
126
                if ($parenthesis == $parenthesisRemoved) {
127
                    $trim[$i] = ' ';
128
                    --$parenthesisRemoved;
129
                }
130
                --$parenthesis;
131
            }
132
            ++$i;
133
        }
134
135
        return trim($trim);
136
    }
137
138
    public function getLastOf($array)
139
    {
140
        // $array is a copy of the original array, so we can change it without sideeffects
141
        if (!is_array($array)) {
142
            return false;
143
        }
144
145
        return array_pop($array);
146
    }
147
148
    /**
149
     * translates an array of objects into an associative array.
150
     */
151
    public function toArray($tokenList)
152
    {
153
        $expr = array();
154
        foreach ($tokenList as $token) {
155
            $expr[] = $token->toArray();
156
        }
157
158
        return (empty($expr) ? false : $expr);
159
    }
160
}
161