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

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
 * This file is a part of Woketo package.
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\Woketo\Http;
13
14
use Nekland\Tools\StringTools;
15
16
/**
17
 * Class Url
18
 *
19
 * Represent a WebSocket URL
20
 *
21
 * @internal
22
 */
23
class Url
24
{
25
    /**
26
     * @var bool
27
     */
28
    private $secured;
29
30
    /**
31
     * example: 127.0.0.1
32
     *
33
     * @var string
34
     */
35
    private $host;
36
37
    /**
38
     * example: 8080
39
     *
40
     * @var int
41
     */
42
    private $port;
43
44
    /**
45
     * example: /chat
46
     *
47
     * @var string
48
     */
49
    private $uri;
50
51 8
    public function __construct(string $url = null)
52
    {
53 8
        if (null !== $url) {
54 8
            $this->initialize($url);
55
        }
56 8
    }
57
58
    /**
59
     * @return bool
60
     */
61 1
    public function isSecured(): bool
62
    {
63 1
        return $this->secured;
64
    }
65
66
    /**
67
     * @param bool $secured
68
     * @return Url
69
     */
70 1
    public function setSecured(bool $secured = true)
71
    {
72 1
        $this->secured = $secured;
73
74 1
        return $this;
75
    }
76
77
    /**
78
     * @return string
79
     */
80 4
    public function getHost(): string
81
    {
82 4
        return $this->host;
83
    }
84
85
    /**
86
     * @param string $host
87
     * @return Url
88
     */
89 1
    public function setHost(string $host)
90
    {
91 1
        $this->host = $host;
92
93 1
        return $this;
94
    }
95
96
    /**
97
     * @return int
98
     */
99 4
    public function getPort(): int
100
    {
101 4
        return $this->port;
102
    }
103
104
    /**
105
     * @param int $port
106
     * @return Url
107
     */
108
    public function setPort(int $port)
109
    {
110
        $this->port = $port;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @return string
117
     */
118 6
    public function getUri(): string
119
    {
120 6
        return $this->uri;
121
    }
122
123
    /**
124
     * @param string $uri
125
     * @return Url
126
     */
127
    public function setUri($uri)
128
    {
129
        $this->uri = $uri;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Fill the object with given URL as string.
136
     *
137
     * @param string $url
138
     */
139 8
    private function initialize(string $url)
140
    {
141 8
        $match = preg_match('/^wss?:\/\/(.+):([\d]{2,5})(\/.+)?/', $url, $matches);
142
143 8
        if ($match !== 1 || !in_array(count($matches), [3, 4])) {
144
            throw new \InvalidArgumentException(sprintf('The URL %s is invalid.', $url));
145
        }
146
147 8
        $this->secured = StringTools::startsWith($url, 'wss');
148 8
        $this->host = $matches[1];
149 8
        $this->port = $matches[2];
0 ignored issues
show
Documentation Bug introduced by
The property $port was declared of type integer, but $matches[2] is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
150 8
        $this->uri = isset($matches[3]) ? $matches[3] : '/';
151 8
    }
152
153
    /**
154
     * @return string
155
     */
156 2
    public function __toString()
157
    {
158 2
        $str = $this->secured ? 'wss://' : 'ws://';
159 2
        $str .= $this->host . ':' . $this->port . $this->uri;
160
161 2
        return $str;
162
    }
163
}
164