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/Weew/Url/UrlBuilder.php (5 issues)

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 Weew\Url;
4
5
class UrlBuilder implements IUrlBuilder {
6
    /**
7
     * @var string
8
     */
9
    protected $pattern = ':scheme:credentials:host:port:path:query:fragment';
10
11
    /**
12
     * @param IUrl $url
13
     * @param bool $encode
14
     *
15
     * @return string
16
     */
17
    public function build(IUrl $url, $encode = false) {
18
        $pattern = $this->pattern;
19
        $pattern = $this->setProtocol($pattern, $url, $encode);
20
        $pattern = $this->setCredentials($pattern, $url, $encode);
21
        $pattern = $this->setHost($pattern, $url, $encode);
22
        $pattern = $this->setPort($pattern, $url, $encode);
23
        $pattern = $this->setPath($pattern, $url, $encode);
24
        $pattern = $this->setQuery($pattern, $url, $encode);
25
        $pattern = $this->setFragment($pattern, $url, $encode);
26
27
        return $pattern;
28
    }
29
30
    /**
31
     * @param string $tld
32
     * @param string $domain
33
     * @param string $subdomain
34
     *
35
     * @return string
36
     */
37
    public function buildHost($tld, $domain, $subdomain) {
38
        $parts = [];
39
40
        if ($tld !== null) {
41
            array_unshift($parts, $tld);
42
        }
43
44
        if ($domain !== null) {
45
            array_unshift($parts, $domain);
46
        }
47
48
        if ($subdomain !== null) {
49
            array_unshift($parts, $subdomain);
50
        }
51
52
        $host = implode('.', $parts);
53
54
        return $host;
55
    }
56
57
    /**
58
     * @param string $pattern
59
     * @param IUrl $url
60
     * @param bool $encode
61
     * @param string $key
62
     *
63
     * @return string
64
     */
65
    protected function setProtocol($pattern, IUrl $url, $encode = false, $key = ':scheme') {
0 ignored issues
show
The parameter $encode 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...
66
        $scheme = $url->getProtocol();
67
68
        if ($scheme) {
69
            $scheme = s('%s://', $scheme);
70
        }
71
72
        $pattern = s($pattern, [$key => $scheme]);
73
74
        return $pattern;
75
    }
76
77
    /**
78
     * @param string $pattern
79
     * @param IUrl $url
80
     * @param bool $encode
81
     * @param string $key
82
     *
83
     * @return string
84
     */
85
    protected function setCredentials($pattern, IUrl $url, $encode = false, $key = ':credentials') {
86
        $username = $url->getUsername();
87
        $password = $url->getPassword();
88
        $credentials = '';
89
90
        if ($encode) {
91
            $username = rawurlencode($username);
92
            $password = rawurlencode($password);
93
        }
94
95
        if ($username && $password) {
96
            $credentials = s('%s:%s@', $username, $password);
97
        }
98
99
        $pattern = s($pattern, [$key => $credentials]);
100
101
        return $pattern;
102
    }
103
104
    /**
105
     * @param string $pattern
106
     * @param IUrl $url
107
     * @param bool $encode
108
     * @param string $key
109
     *
110
     * @return string
111
     */
112
    protected function setHost($pattern, IUrl $url, $encode = false, $key = ':host') {
0 ignored issues
show
The parameter $encode 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...
113
        $host = $url->getHost();
114
        $pattern = s($pattern, [$key => $host]);
115
116
        return $pattern;
117
    }
118
119
    /**
120
     * @param string $pattern
121
     * @param IUrl $url
122
     * @param bool $encode
123
     * @param string $key
124
     *
125
     * @return string
126
     */
127
    protected function setPort($pattern, IUrl $url, $encode = false, $key = ':port') {
0 ignored issues
show
The parameter $encode 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...
128
        $port = $url->getPort();
129
130
        if ($port) {
131
            $port = s(':%s', $port);
132
        }
133
134
        $pattern = s($pattern, [$key => $port]);
135
136
        return $pattern;
137
    }
138
139
    /**
140
     * @param string $pattern
141
     * @param IUrl $url
142
     * @param bool $encode
143
     * @param string $key
144
     *
145
     * @return string
146
     */
147
    protected function setPath($pattern, IUrl $url, $encode = false, $key = ':path') {
0 ignored issues
show
The parameter $encode 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...
148
        $path = $url->getPath();
149
        $pattern = s($pattern, [$key => $path]);
150
151
        return $pattern;
152
    }
153
154
    /**
155
     * @param string $pattern
156
     * @param IUrl $url
157
     * @param bool $encode
158
     * @param string $key
159
     *
160
     * @return string
161
     */
162
    protected function setQuery($pattern, IUrl $url, $encode = false, $key = ':query') {
163
        $query = $url->getQuery()->toString($encode);
164
165
        if ($query) {
166
            $query = s('?%s', $query);
167
        }
168
169
        $pattern = s($pattern, [$key => $query]);
170
171
        return $pattern;
172
    }
173
174
    /**
175
     * @param string $pattern
176
     * @param IUrl $url
177
     * @param bool $encode
178
     * @param string $key
179
     *
180
     * @return string
181
     */
182
    protected function setFragment($pattern, IUrl $url, $encode = false, $key = ':fragment') {
0 ignored issues
show
The parameter $encode 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...
183
        $fragment = $url->getFragment();
184
185
        if ($fragment) {
186
            $fragment = s('#%s', $fragment);
187
        }
188
189
        $pattern = s($pattern, [$key => $fragment]);
190
191
        return $pattern;
192
    }
193
}
194