Issues (3)

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/Url/Url.php (1 issue)

Labels
Severity

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 AnthonySan95\UrlSigner\Url;
4
5
use Illuminate\Support\Arr;
6
use InvalidArgumentException;
7
use MalformedUrlException;
8
9
class Url {
10
11
    protected $parsedUrl;
12
13
    /**
14
     * Url constructor.
15
     * @param $url
16
     * @param array $parameters
17
     * @throws \Throwable
18
     */
19
    public function __construct($url, $parameters = []) {
20
        throw_if(empty($url), InvalidArgumentException::class);
21
22
        $this->parsedUrl = parse_url($url);
23
24
        throw_if(!is_array($this->parsedUrl), MalformedUrlException::class);
25
26
        if (isset($this->parsedUrl['query'])) {
27
            parse_str($this->parsedUrl['query'], $this->parsedUrl['query']);
28
        }
29
30
        if (isset($parameters)) {
31
            if (empty($this->parsedUrl['query'])) {
32
                $this->parsedUrl['query'] = [];
33
            }
34
35
            $this->parsedUrl['query'] += $parameters;
36
        }
37
38
        if (isset($this->parsedUrl['query'])) {
39
            ksort($this->parsedUrl['query']);
40
        }
41
    }
42
43
    /**
44
     * Get the scheme of this url or an empty string if unset.
45
     *
46
     * @return string
47
     */
48
    public function scheme() {
49
        return $this->parsedUrl['scheme'] ?? '';
50
    }
51
52
    /**
53
     * Get the host of this url or an empty string if unset.
54
     *
55
     * @return string
56
     */
57
    public function host() {
58
        return $this->parsedUrl['host'] ?? '';
59
    }
60
61
    /**
62
     * Get the port of this url or an empty string if unset.
63
     *
64
     * @return string
65
     */
66
    public function port() {
67
        return $this->parsedUrl['port'] ?? '';
68
    }
69
70
    /**
71
     * Get the user of this url or an empty string if unset.
72
     *
73
     * @return string
74
     */
75
    public function user() {
76
        return $this->parsedUrl['user'] ?? '';
77
    }
78
79
    /**
80
     * Get the pass of this url or an empty string if unset.
81
     *
82
     * @return string
83
     */
84
    public function pass() {
85
        return $this->parsedUrl['pass'] ?? '';
86
    }
87
88
    /**
89
     * Get the path of this url or an empty string if unset.
90
     *
91
     * @return string
92
     */
93
    public function path() {
94
        return $this->parsedUrl['path'] ?? '';
95
    }
96
97
    /**
98
     * Retrieve a query string item from the request.
99
     *
100
     * @param  string $key
101
     * @param  string $default
102
     * @return string|array|null
103
     */
104
    public function query($key = null, $default = null) {
105
        if (empty($this->parsedUrl['query'])) {
106
            if (!is_null($key)) {
107
                return $default;
108
            }
109
110
            return [];
111
        }
112
113
        if (is_null($key)) {
114
            return $this->parsedUrl['query'];
115
        }
116
117
        return $this->parsedUrl['query'][$key] ?? $default;
118
    }
119
120
    /**
121
     * Get the fragment of this url or an empty string if unset.
122
     *
123
     * @return string
124
     */
125
    public function fragment() {
126
        return $this->parsedUrl['fragment'] ?? '';
127
    }
128
129
    /**
130
     * Obtain a string made out of this Url.
131
     *
132
     * @param bool $withQuery
133
     * @return string
134
     */
135
    public function get($withQuery = true) {
136
        // Ex url. http://usr:[email protected]:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment
137
138
        return
139
            ($this->scheme() ? $this->scheme() . '://' : '') .
140
            $this->user() .
141
            ($this->pass() ? ':' . $this->pass() : '') .
142
            (($this->user() || $this->pass()) ? '@' : '') .
143
            $this->host() .
144
            ($this->port() ? ':' . $this->port() : '') .
145
            $this->path() .
146
            ($withQuery && $this->query() ? '?' . Arr::query($this->query()) : '') .
0 ignored issues
show
It seems like $this->query() targeting AnthonySan95\UrlSigner\Url\Url::query() can also be of type string; however, Illuminate\Support\Arr::query() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
147
            ($this->fragment() ? '#' . $this->fragment() : '');
148
    }
149
150
    /**
151
     * Obtain a string made out of this Url without queries.
152
     *
153
     * @return string
154
     */
155
    public function getWithoutQuery() {
156
        return $this->get(false);
157
    }
158
159
    /**
160
     * To string magic function, automatically called when casting to string.
161
     *
162
     * @return string
163
     */
164
    public function __toString() {
165
        return $this->get();
166
    }
167
}
168