Issues (11)

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/Utility/StringUtils.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
namespace JimmyOak\Utility;
4
5
class StringUtils extends UtilsBase
6
{
7
    const CASE_INSENSITIVE   = 1;
8
    const ACCENT_INSENSITIVE = 2;
9
10
    private $accentsMap = array(
11
        'Š' => 'S',
12
        'š' => 's',
13
        'Ž' => 'Z',
14
        'ž' => 'z',
15
        'À' => 'A',
16
        'Á' => 'A',
17
        'Â' => 'A',
18
        'Ã' => 'A',
19
        'Ä' => 'A',
20
        'Å' => 'A',
21
        'Æ' => 'A',
22
        'Ç' => 'C',
23
        'È' => 'E',
24
        'É' => 'E',
25
        'Ê' => 'E',
26
        'Ë' => 'E',
27
        'Ì' => 'I',
28
        'Í' => 'I',
29
        'Î' => 'I',
30
        'Ï' => 'I',
31
        'Ñ' => 'N',
32
        'Ò' => 'O',
33
        'Ó' => 'O',
34
        'Ô' => 'O',
35
        'Õ' => 'O',
36
        'Ö' => 'O',
37
        'Ø' => 'O',
38
        'Ù' => 'U',
39
        'Ú' => 'U',
40
        'Û' => 'U',
41
        'Ü' => 'U',
42
        'Ý' => 'Y',
43
        'Þ' => 'B',
44
        'ß' => 'Ss',
45
        'à' => 'a',
46
        'á' => 'a',
47
        'â' => 'a',
48
        'ã' => 'a',
49
        'ä' => 'a',
50
        'å' => 'a',
51
        'æ' => 'a',
52
        'ç' => 'c',
53
        'è' => 'e',
54
        'é' => 'e',
55
        'ê' => 'e',
56
        'ë' => 'e',
57
        'ì' => 'i',
58
        'í' => 'i',
59
        'î' => 'i',
60
        'ï' => 'i',
61
        'ð' => 'o',
62
        'ñ' => 'n',
63
        'ò' => 'o',
64
        'ó' => 'o',
65
        'ô' => 'o',
66
        'õ' => 'o',
67
        'ö' => 'o',
68
        'ø' => 'o',
69
        'ù' => 'u',
70
        'ú' => 'u',
71
        'û' => 'u',
72
        'ý' => 'y',
73
        'þ' => 'b',
74
        'ÿ' => 'y'
75
    );
76
77
    private $urlRegExp;
78
    private $emailRegExp;
79
80
    protected function __construct()
81
    {
82
        $this->urlRegExp = '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|' .
83
            '(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{0' .
84
            '0a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6})' .
85
            ')(?::\d+)?(?:[^\s]*)?$%iu';
86
87
        $this->emailRegExp = '/^([a-z0-9_.-])+@([a-z0-9_.-])+\.([a-z])+([a-z])+/i';
88
    }
89
90
    /**
91
     * @param string $haystack
92
     * @param string $needle
93
     * @param int|null $modifiers
94
     *
95
     * @return bool
96
     */
97 View Code Duplication
    public function beginsWith($haystack, $needle, $modifiers = null)
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...
98
    {
99
        $this->prepareHaystackAndNeedle($haystack, $needle, $modifiers);
100
        $parsedModifiers = $this->parseModifiers($modifiers);
101
102
        $pattern = '/^' . preg_quote($needle) . '/';
103
104
        return (bool)preg_match($pattern . $parsedModifiers, $haystack);
105
    }
106
107
    /**
108
     * @param string $string
109
     *
110
     * @return string
111
     */
112
    public function removeAccents($string)
113
    {
114
        return strtr($string, $this->accentsMap);
115
    }
116
117
    /**
118
     * @param string $haystack
119
     * @param string $needle
120
     * @param int|null $modifiers
121
     *
122
     * @return bool
123
     */
124 View Code Duplication
    public function endsWith($haystack, $needle, $modifiers = null)
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...
125
    {
126
        self::prepareHaystackAndNeedle($haystack, $needle, $modifiers);
127
        $parsedModifiers = $this->parseModifiers($modifiers);
128
129
        $pattern = '/' . preg_quote($needle) . '$/';
130
131
        return (bool)preg_match($pattern . $parsedModifiers, $haystack);
132
    }
133
134
    /**
135
     * @param string $string
136
     *
137
     * @return string
138
     */
139
    public function removeExtraSpaces($string)
140
    {
141
        return trim(preg_replace('/\s+/', ' ', $string));
142
    }
143
144
    /**
145
     * @param string $string
146
     *
147
     * @return bool
148
     */
149
    public function isUrl($string)
150
    {
151
        return preg_match($this->urlRegExp, $string) > 0;
152
    }
153
154
    /**
155
     * @param string $string
156
     *
157
     * @return bool
158
     */
159
    public function isEmail($string)
160
    {
161
        return preg_match($this->emailRegExp, $string) > 0;
162
    }
163
164
    private function parseModifiers($modifiers)
165
    {
166
        $parsedModifiers = '';
167
168
        if ($modifiers & self::CASE_INSENSITIVE) {
169
            $parsedModifiers .= 'i';
170
        }
171
172
        return $parsedModifiers;
173
    }
174
175
    private function isAccentInsensitiveModifier($modifiers)
176
    {
177
        return $modifiers & self::ACCENT_INSENSITIVE;
178
    }
179
180
    private function prepareHaystackAndNeedle(&$haystack, &$needle, $modifiers)
181
    {
182
        if ($this->isAccentInsensitiveModifier($modifiers)) {
183
            $haystack = $this->removeAccents($haystack);
184
            $needle   = $this->removeAccents($needle);
185
        }
186
    }
187
}
188