Issues (6)

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/Server/ZeroMqServer.php (2 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
3
namespace AsyncPHP\Remit\Server;
4
5
use AsyncPHP\Remit\Event;
6
use AsyncPHP\Remit\Event\InMemoryEvent;
7
use AsyncPHP\Remit\Location;
8
use AsyncPHP\Remit\Server;
9
use Closure;
10
use Exception;
11
use ZMQ;
12
use ZMQContext;
13
use ZMQSocket;
14
15
final class ZeroMqServer implements Server
16
{
17
    /**
18
     * @var Location
19
     */
20
    private $location;
21
22
    /**
23
     * @var ZMQSocket
24
     */
25
    private $socket;
26
27
    /**
28
     * @var array
29
     */
30
    private $listeners = [];
31
32
    /**
33
     * @param Location $location
34
     */
35 2
    public function __construct(Location $location)
36
    {
37 2
        $this->location = $location;
38 2
    }
39
40
    /**
41
     * @inheritdoc
42
     *
43
     * @param string $name
44
     * @param Closure $closure
45
     *
46
     * @return $this
47
     */
48 1
    public function addListener($name, Closure $closure)
49
    {
50 1
        if (empty($this->listeners[$name])) {
51 1
            $hash = spl_object_hash($closure);
52
53 1
            $this->listeners[$name][$hash] = $closure;
54 1
        }
55
56 1
        return $this;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     *
62
     * @param string $name
63
     * @param Closure $closure
64
     */
65 1
    public function removeListener($name, Closure $closure)
66
    {
67 1
        $hash = spl_object_hash($closure);
68
69 1
        if (isset($this->listeners[$name]) && isset($this->listeners[$name][$hash])) {
70 1
            unset($this->listeners[$name][$hash]);
71 1
        }
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79 1
    public function tick()
80
    {
81 1
        $socket = $this->getSocket();
82
83 1
        if (!($event = $socket->recv(ZMQ::MODE_DONTWAIT))) {
84 1
            return;
85
        }
86
87 1
        $event = @unserialize($event);
88
89 1
        if ($event instanceof Event) {
90 1
            $this->dispatchEvent($event);
91 1
        }
92 1
    }
93
94
    /**
95
     * @return ZMQSocket
96
     */
97 1 View Code Duplication
    private function getSocket()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99 1
        if ($this->socket === null) {
100 1
            $context = new ZMQContext();
101
102 1
            $host = $this->location->getHost();
103 1
            $port = $this->location->getPort();
104
105 1
            $this->socket = new ZMQSocket($context, ZMQ::SOCKET_PULL, spl_object_hash($this));
106 1
            $this->socket->bind("tcp://{$host}:$port");
107 1
        }
108
109 1
        return $this->socket;
110
    }
111
112
    /**
113
     * @param Event $event
114
     *
115
     * @return $this
116
     */
117 1
    private function dispatchEvent(Event $event)
118
    {
119 1
        $name = $event->getName();
120
121 1
        if (isset($this->listeners[$name])) {
122 1
            foreach ($this->listeners[$name] as $closure) {
123 1
                call_user_func_array($closure, $event->getParameters());
124 1
            }
125 1
        }
126
127 1
        return $this;
128
    }
129
130
    /**
131
     * @inheritdoc
132
     *
133
     * @param string $name
134
     * @param array $parameters
135
     *
136
     * @return $this
137
     */
138
    public function emit($name, array $parameters = [])
139
    {
140
        return $this->dispatchEvent(
141
            new InMemoryEvent($name, $parameters)
142
        );
143
    }
144
145
    /**
146
     * @inheritdoc
147
     *
148
     * @return string
149
     */
150 1
    public function serialize()
151
    {
152 1
        return serialize($this->location);
153
    }
154
155
    /**
156
     * @inheritdoc
157
     *
158
     * @param string $serialized
159
     */
160 1
    public function unserialize($serialized)
161
    {
162 1
        $this->location = unserialize($serialized);
163 1
    }
164
165
    /**
166
     * @return Location
167
     */
168
    public function getLocation()
169
    {
170
        return $this->location;
171
    }
172
173
    /**
174
     * @inheritdoc
175
     */
176 1 View Code Duplication
    public function disconnect()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
    {
178 1
        if ($this->socket) {
179
            try {
180
                $host = $this->location->getHost();
181
                $port = $this->location->getPort();
182
183
                $this->socket->disconnect("tcp://{$host}:{$port}");
184
            } catch (Exception $exception) {
185
                // TODO: find an elegant way to deal with this
186
            }
187
        }
188 1
    }
189
190 1
    public function __destruct()
191
    {
192 1
        $this->disconnect();
193 1
    }
194
}
195