Issues (25)

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/StreamFactory.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
declare(strict_types=1);
3
4
namespace FakeSocket;
5
6
use FakeSocket\{
7
    CanCopy,
0 ignored issues
show
This use statement conflicts with another class in this namespace, FakeSocket\CanCopy.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
    StreamException,
0 ignored issues
show
This use statement conflicts with another class in this namespace, FakeSocket\StreamException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
    StreamWrapper,
0 ignored issues
show
This use statement conflicts with another class in this namespace, FakeSocket\StreamWrapper.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
    Stream\Buffer
11
};
12
use InvalidArgumentException;
13
14
final class StreamFactory
15
{
16
    use CanCopy;
17
18
    /** @const int */
19
    private const MIN_PORT = 1;
20
21
    /** @const int 16bit */
22
    private const MAX_PORT = 65535;
23
24
    /** @var string */
25
    private $protocol;
26
27
    /** @var string */
28
    private $spec;
29
30
    /** @var string */
31
    private $host;
32
33
    /** @var int */
34
    private $port;
35
36
    /** @var int */
37
    private $read;
38
39
    /** @var int */
40
    private $readAfter;
41
42
    /** @var int */
43
    private $readEvery;
44
45
    /** @var int */
46
    private $write;
47
48
    /** @var int */
49
    private $writeAfter;
50
51
    /** @var int */
52
    private $writeEvery;
53
54 24
    public static function make(string $dataSourceName): self
55
    {
56 24
        $components = parse_url($dataSourceName);
57
58 24
        $host = $components['host'] ?? $components['path'];
59
60 24
        if (!isset($host)) {
61 1
            throw StreamException::invalidDataSource();
62
        }
63
64 23
        static $defaultSpec = Buffer::class;
65
66 23
        $factory = new self($defaultSpec);
67 23
        $factory->protocol = $components['scheme'] ?? 'fake';
68 23
        $factory->host = $host;
69
70 23
        if (isset($components['port'])) {
71 1
            $factory = $factory->withPort($components['port']);
72
        }
73
74 23
        return $factory;
75
    }
76
77 24
    public function __construct(string $spec)
78
    {
79 24
        if (!is_subclass_of($spec, StreamWrapper::class)) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \FakeSocket\StreamWrapper::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
80 1
            throw StreamException::invalidClass($spec);
81
        }
82
83 23
        $this->spec = $spec;
84 23
    }
85
86 13
    public function register(): string
87
    {
88 13
        if (in_array($this->protocol, stream_get_wrappers())) {
89 12
            stream_wrapper_unregister($this->protocol);
90
        }
91
92 13
        stream_wrapper_register($this->protocol, $this->spec);
93
94 13
        if (isset($this->port)) {
95 1
            $this->host = "{$this->host}:{$this->port}";
96
        }
97
98
        $query = [
99 13
            'read'        => $this->read,
100 13
            'read_after'  => $this->readAfter,
101 13
            'read_every'  => $this->readEvery,
102 13
            'write'       => $this->write,
103 13
            'write_after' => $this->writeAfter,
104 13
            'write_every' => $this->writeEvery,
105
        ];
106
107 13
        $query = http_build_query($query);
108 13
        empty($query) ?: $query = "/?$query";
109
110 13
        return "{$this->protocol}://{$this->host}{$query}";
111
    }
112
113 2
    public function withProtocol(string $protocol): self
114
    {
115 2
        return $this->copy('protocol', $protocol);
116
    }
117
118 2
    public function withHost(string $host): self
119
    {
120 2
        return $this->copy('host', $host);
121
    }
122
123 5
    public function withPort(int $port): self
124
    {
125 5
        if ($port < self::MIN_PORT || $port > self::MAX_PORT) {
126 3
            throw StreamException::invalidPortRange(
127 3
                self::MIN_PORT,
128 3
                self::MAX_PORT
129
            );
130
        }
131
132 2
        return $this->copy('port', $port);
133
    }
134
135 3
    public function withRead(int $limit = -1): self
136
    {
137 3
        return $this->copy('read', $limit);
138
    }
139
140 4
    public function withWrite(int $limit = -1): self
141
    {
142 4
        return $this->copy('write', $limit);
143
    }
144
145 1
    public function withoutRead(): self
146
    {
147 1
        return $this->copy('read', 0);
148
    }
149
150 1
    public function withoutWrite(): self
151
    {
152 1
        return $this->copy('write', 0);
153
    }
154
155 1
    public function withReadAfter(int $limit = 0): self
156
    {
157 1
        return $this->copy('readAfter', $limit);
158
    }
159
160 1
    public function withWriteAfter(int $limit = 0): self
161
    {
162 1
        return $this->copy('writeAfter', $limit);
163
    }
164
165 1
    public function withReadEvery(int $limit = 1): self
166
    {
167 1
        return $this->copy('readEvery', $limit);
168
    }
169
170 2
    public function withWriteEvery(int $limit = 1): self
171
    {
172 2
        return $this->copy('writeEvery', $limit);
173
    }
174
}
175