Issues (42)

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.

src/Helpers/URI.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
namespace Almendra\Http\Helpers;
4
5
use Psr\Http\Message\UriInterface as PsrUri;
6
7
class URI
8
{
9
    /**
10
     * Retrieve the parameters from the URI
11
     *
12
     * @param string $uri 		    The URI
13
     * @param boolean $serialized   It's to be serialized?
14
     * @return mixed
15
     */
16
    public static function getQueryParams($uri, $serialized = true)
17
    {
18
        $params = '';
19
20
        // do parameters exist?
21
        if (strstr($uri, '?')) {
22
            $params = substr($uri, strpos($uri, '?') + 1);
23
        }
24
25
        // check the parameters
26
        if (!self::isQueryParamsValid($params)) {
27
            throw new \InvalidArgumentException("Invalid query parameters");
28
        }
29
30
        if (!$serialized) {
31
            $params = static::deserializeQueryParams($params);
32
        }
33
34
        return $params;
35
    }
36
37
    /**
38
     * Returns the query params as an associative array
39
     *
40
     * @param string $params 		The query parameters
41
     * @return array
42
     */
43
    public static function deserializeQueryParams($params)
44
    {
45
        $fields = [];
46
47
        $params = explode('&', $params);
48
        foreach ($params as $param) {
49
            $parts = explode('=', $param);
50
51
            // eliminate not defined parameters
52
            if (count($parts) != 2) {
53
                continue;
54
            } elseif (null === $parts[0] || '' === $parts[0]) {
55
                continue;
56
            }
57
58
            $fields[$parts[0]] = $parts[1];
59
        }
60
61
        return $fields;
62
    }
63
64
    /**
65
     * Serializes the query params
66
     *
67
     * @param array $queryParams 		The query params
68
     * @return string
69
     */
70
    public static function serializeQueryParams(array $queryParams)
71
    {
72
        $params = '';
73
        foreach ($queryParams as $key => $value) {
74
            $params .= $key . '=' . $value . '&';
75
        }
76
77
        return substr($params, 0, -1);
78
    }
79
80
    /**
81
     * Check query parameters validity
82
     *
83
     * @param string $params 		The query parameters
84
     * @return boolean 				true if valid
85
     */
86
    public static function isQueryParamsValid($params)
87
    {
88
        if (is_array($params)) {
89
            throw new \InvalidArgumentException("Query parameters must be an string");
90
        }
91
92
        $params = self::deserializeQueryParams($params);
0 ignored issues
show
$params 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...
93
        
94
        return true;
95
    }
96
97
    /**
98
     * Percentage encode a query.
99
     *
100
     * @param string $query 		The query to be encoded.
101
     * @return string
102
     */
103
    public static function percentEncode($query)
104
    {
105
        return htmlentities(strip_tags($query), ENT_QUOTES);
106
    }
107
108
    public static function isQueryValid($query)
109
    {
110
        if (!is_string($query) && !method_exists($query, '__toString')) {
111
            return false;
112
        }
113
114
        return true;
115
    }
116
117
    public static function isValid($uri)
118
    {
119
        if (!($uri instanceof PsrUri) && !is_string($uri)) {
120
            return false;
121
        }
122
123
        return true;
124
    }
125
126
    /**
127
     * Retrieve the fragment from the URI
128
     *
129
     * @param string $uri 		The URI
130
     * @return string
131
     */
132
    public static function getQueryFragment($uri)
0 ignored issues
show
The parameter $uri is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
133
    {
134
        return null;
135
    }
136
137
    /**
138
     * Validates a port within TCP and UDP ranges.
139
     *
140
     * @param string $port         The port
141
     * @return boolean
142
     */
143
    public static function isPortValid($port)
0 ignored issues
show
The parameter $port is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
144
    {
145
        return true;
146
    }
147
148
    /**
149
     * Validates a path.
150
     *
151
     * @param string $path         The path
152
     * @return boolean
153
     */
154
    public static function isPathValid($path)
0 ignored issues
show
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
155
    {
156
        return true;
157
    }
158
159
    public function validator()
160
    {
161
        return [
162
            'name' => [
163
                'min' => 255,
164
                ],
165
166
            'value' => [
167
                ],
168
            ];
169
    }
170
}
171