Issues (74)

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/Protocol/AbstractConnection.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
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol;
5
6
use Genkgo\Mail\Exception\CannotWriteToStreamException;
7
use Genkgo\Mail\Exception\ConnectionBrokenException;
8
use Genkgo\Mail\Exception\ConnectionTimeoutException;
9
use Genkgo\Mail\Exception\ConnectionClosedException;
10
11
/**
12
 * @codeCoverageIgnore
13
 */
14
abstract class AbstractConnection implements ConnectionInterface
15
{
16
    private const RECEIVE_BYTES = 1024;
17
18
    /**
19
     * @var resource|null
20
     */
21
    protected $resource;
22
23
    /**
24
     * @var array<string, array<int, \Closure>>
25
     */
26
    private $listeners = [
27
        'connect' => []
28
    ];
29
    
30
    final public function __destruct()
31
    {
32
        $this->disconnect();
33
    }
34
35
    /**
36
     * @param string $name
37
     * @param \Closure $callback
38
     */
39
    final public function addListener(string $name, \Closure $callback): void
40
    {
41
        $this->listeners[$name][] = $callback;
42
    }
43
44
    /**
45
     * @param string $name
46
     */
47
    final protected function fireEvent(string $name): void
48
    {
49
        if (!isset($this->listeners[$name])) {
50
            return;
51
        }
52
53
        foreach ($this->listeners[$name] as $listener) {
54
            $listener();
55
        }
56
    }
57
    
58
    abstract public function connect(): void;
59
    
60
    final public function disconnect(): void
61
    {
62
        if ($this->resource !== null) {
63
            \fclose($this->resource);
64
            $this->resource = null;
65
        }
66
    }
67
68
    /**
69
     * @param float $timeout
70
     */
71
    final public function timeout(float $timeout): void
72
    {
73
        \stream_set_timeout($this->verifyConnection(), (int)$timeout);
74
    }
75
76
    /**
77
     * @param string $request
78
     * @return int
79
     * @throws CannotWriteToStreamException
80
     */
81
    final public function send(string $request): int
82
    {
83
        $bytesWritten = \fwrite($this->verifyConnection(), $request);
84
85
        if ($bytesWritten === false) {
86
            throw new CannotWriteToStreamException();
87
        }
88
89
        return $bytesWritten;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    final public function receive(): string
96
    {
97
        $response = \fgets($this->verifyConnection(), self::RECEIVE_BYTES);
98
99
        $this->verifyAlive();
100
101
        if ($response === false) {
102
            throw new ConnectionBrokenException('Cannot receive information');
103
        }
104
105
        return $response;
106
    }
107
108
    /**
109
     * @param array<int, string> $keys
110
     * @return array<string, mixed>
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
111
     */
112
    final public function getMetaData(array $keys = []): array
113
    {
114
        $resource = $this->verifyAlive();
115
116
        $metaData = \stream_get_meta_data($resource);
117
118
        $keys = \array_map('strtolower', $keys);
119
120
        return \array_filter(
121
            $metaData,
122
            function ($key) use ($keys) {
123
                return \in_array(\strtolower($key), $keys);
124
            },
125
            ARRAY_FILTER_USE_KEY
126
        );
127
    }
128
129
    /**
130
     * @return resource
131
     */
132
    private function verifyConnection()
133
    {
134
        if ($this->resource === null) {
135
            throw new \UnexpectedValueException('Cannot communicate when there is no connection');
136
        }
137
138
        return $this->resource;
139
    }
140
141
    /**
142
     * @return resource
143
     * @throws ConnectionClosedException
144
     * @throws ConnectionTimeoutException
145
     */
146
    private function verifyAlive()
147
    {
148
        $resource = $this->verifyConnection();
149
        $info = \stream_get_meta_data($resource);
150
        if ($info['timed_out']) {
151
            throw new ConnectionTimeoutException('Connection has timed out');
152
        }
153
154
        if ($info['eof']) {
155
            throw new ConnectionClosedException('Connection is gone');
156
        }
157
158
        return $resource;
159
    }
160
}
161