Issues (245)

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/Utils/Parser.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
/**
4
 * \AppserverIo\Doppelgaenger\Utils\Parser
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Bernhard Wick <[email protected]>
15
 * @copyright 2015 TechDivision GmbH - <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/doppelgaenger
18
 * @link      http://www.appserver.io/
19
 */
20
21
namespace AppserverIo\Doppelgaenger\Utils;
22
23
/**
24
 * Will provide basic parsing methods for analyzing and code structures
25
 *
26
 * @author    Bernhard Wick <[email protected]>
27
 * @copyright 2015 TechDivision GmbH - <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/appserver-io/doppelgaenger
30
 * @link      http://www.appserver.io/
31
 */
32
class Parser
33
{
34
35
    /**
36
     * Will get the count of certain brackets within a string.
37
     * Will return an integer which is calculated as the number of opening brackets against closing ones.
38
     *
39
     * @param string $string      The string to search in
40
     * @param string $bracketType A bracket to be taken as general bracket type e.g. '('
41
     *
42
     * @return integer
43
     */
44
    public function getBracketCount($string, $bracketType)
45
    {
46
        // prepare opening and closing bracket according to bracket type
47 View Code Duplication
        switch ($bracketType) {
48
            case '(':
49
            case ')':
50
                $openingBracket = '(';
51
                $closingBracket = ')';
52
                break;
53
54
            case '{':
55
            case '}':
56
                $openingBracket = '{';
57
                $closingBracket = '}';
58
                break;
59
60
            case '[':
61
            case ']':
62
                $openingBracket = '[';
63
                $closingBracket = ']';
64
                break;
65
66
            default:
67
                throw new \Exception(sprintf('Unrecognized bracket type %s', $bracketType));
68
        }
69
70
        return substr_count($string, $openingBracket) - substr_count($string, $closingBracket);
71
    }
72
73
    /**
74
     * Will return an integer value representing the length of the first portion of the given string which is completely
75
     * enclosed by a certain bracket type.
76
     * Will return 0 if nothing is found.
77
     *
78
     * @param string  $string      String to investigate
79
     * @param string  $bracketType A bracket to be taken as general bracket type e.g. '('
80
     * @param integer $offset      Offset at which to start looking, will default to 0
81
     *
82
     * @return integer
83
     */
84
    public function getBracketSpan($string, $bracketType, $offset = 0)
85
    {
86
        // prepare opening and closing bracket according to bracket type
87 View Code Duplication
        switch ($bracketType) {
88
            case '(':
89
            case ')':
90
                $openingBracket = '(';
91
                $closingBracket = ')';
92
                break;
93
94
            case '{':
95
            case '}':
96
                $openingBracket = '{';
97
                $closingBracket = '}';
98
                break;
99
100
            case '[':
101
            case ']':
102
                $openingBracket = '[';
103
                $closingBracket = ']';
104
                break;
105
106
            default:
107
                throw new \Exception(sprintf('Unrecognized bracket type %s', $bracketType));
108
        }
109
110
        // split up the string and analyse it character for character
111
        $bracketCounter = null;
112
        $stringArray = str_split($string);
113
        $strlen = strlen($string);
114
        $firstBracket = 0;
115
        for ($i = $offset; $i < $strlen; $i++) {
116
            // count different bracket types by de- and increasing the counter
117
            if ($stringArray[$i] === $openingBracket) {
118
                if (is_null($bracketCounter)) {
119
                    $firstBracket = $i;
120
                }
121
                $bracketCounter = (int) $bracketCounter + 1;
122
0 ignored issues
show
Blank line found at end of control structure
Loading history...
123
            } elseif ($stringArray[$i] === $closingBracket) {
124
                $bracketCounter = (int) $bracketCounter - 1;
125
            }
126
127
            // if we reach 0 again we have a completely enclosed string
128
            if ($bracketCounter === 0) {
129
                return $i + 1 - $firstBracket;
130
            }
131
        }
132
133
        return 0;
134
    }
135
136
    /**
137
     * Will return the length of the string a token array is based on.
138
     *
139
     * @param array $tokens The token array
140
     *
141
     * @return integer
142
     */
143
    public function getStringLength($tokens)
144
    {
145
        // Iterator over the tokens and get their length
146
        $result = 0;
147
        $tokenCount = count($tokens);
148
        for ($i = 0; $i < $tokenCount; $i++) {
149
            if (is_array($tokens[$i])) {
150
                $result += strlen($tokens[$i][1]);
151
0 ignored issues
show
Blank line found at end of control structure
Loading history...
152
            } else {
153
                $result += strlen($tokens[$i]);
154
            }
155
        }
156
157
        return $result;
158
    }
159
}
160