Issues (42)

Security Analysis    not enabled

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/Socket/SocketServer.php (8 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
namespace Dazzle\Http\Socket;
3
4
use Dazzle\Socket\SocketInterface;
5
use Dazzle\Socket\SocketListenerInterface;
6
use Dazzle\Http\Null\NullServer;
7
use Dazzle\Http\NetworkComponentAwareInterface;
8
use Dazzle\Http\NetworkConnection;
9
use Dazzle\Http\NetworkMessage;
10
use Dazzle\Http\NetworkComponentInterface;
11
use Error;
12
use Exception;
13
14
class SocketServer implements SocketServerInterface, NetworkComponentAwareInterface
15
{
16
    /**
17
     * @var SocketListenerInterface
18
     */
19
    protected $socket;
20
21
    /**
22
     * @var NetworkComponentInterface
23
     */
24
    protected $component;
25
26
    /**
27
     * @param NetworkComponentInterface $component
28
     * @param SocketListenerInterface $socket
29
     */
30 55
    public function __construct(SocketListenerInterface $socket, NetworkComponentInterface $component = null)
31
    {
32
33 55
        $this->socket = $socket;
34 55
        $this->component = $component === null ? new NullServer() : $component;
35
36 55
        $socket->on('connect', [ $this, 'handleConnect' ]);
37 55
    }
38
39
    /**
40
     *
41
     */
42 15
    public function __destruct()
43
    {
44 15
        unset($this->socket);
45 15
        unset($this->component);
46 15
    }
47
48
    /**
49
     * @override
50
     * @inheritDoc
51
     */
52 1
    public function start()
53
    {
54 1
        $this->socket->start();
55 1
    }
56
57
    /**
58
     * @override
59
     * @inheritDoc
60
     */
61 3
    public function stop()
62
    {
63 3
        $this->socket->close();
64 3
    }
65
66
    /**
67
     * @override
68
     * @inheritDoc
69
     */
70 24
    public function setComponent(NetworkComponentInterface $component = null)
71
    {
72 24
        $this->component = $component === null ? new NullServer() : $component;
73 24
    }
74
75
    /**
76
     * @override
77
     * @inheritDoc
78
     */
79 3
    public function getComponent()
80
    {
81 3
        return $this->component;
82
    }
83
84
    /**
85
     * Handler triggered when a new connection is received from SocketListener.
86
     *
87
     * @param SocketListenerInterface $server
88
     * @param SocketInterface $socket
89
     */
90 7
    public function handleConnect($server, $socket)
91
    {
92 7
        $socket->conn = new NetworkConnection($socket);
0 ignored issues
show
Accessing conn on the interface Dazzle\Socket\SocketInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
93
94
        try
95
        {
96 7
            $this->component->handleConnect($socket->conn);
0 ignored issues
show
Accessing conn on the interface Dazzle\Socket\SocketInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
97
98 6
            $socket->on('data',  [ $this, 'handleData' ]);
99 6
            $socket->on('error', [ $this, 'handleError' ]);
100 6
            $socket->on('close', [ $this, 'handleDisconnect' ]);
101
        }
102 1
        catch (Error $ex)
103
        {
104
            $this->close($socket);
105
        }
106 1
        catch (Exception $ex)
107
        {
108 1
            $this->close($socket);
109
        }
110 7
    }
111
112
    /**
113
     * Handler triggered when an existing connection is being closed.
114
     *
115
     * @param SocketInterface $socket
116
     */
117 6 View Code Duplication
    public function handleDisconnect($socket)
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...
118
    {
119
        try
120
        {
121 6
            $this->component->handleDisconnect($socket->conn);
0 ignored issues
show
Accessing conn on the interface Dazzle\Socket\SocketInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
122
        }
123 1
        catch (Error $ex)
124
        {
125
            $this->handleError($socket, $ex);
126
        }
127 1
        catch (Exception $ex)
128
        {
129 1
            $this->handleError($socket, $ex);
130
        }
131
132 6
        unset($socket->conn);
133 6
    }
134
135
    /**
136
     * Handler triggered when a new data is received from existing connection.
137
     *
138
     * @param SocketInterface $socket
139
     * @param mixed $data
140
     */
141 6
    public function handleData($socket, $data)
142
    {
143
        try
144
        {
145 6
            $this->component->handleMessage($socket->conn, new NetworkMessage($data));
0 ignored issues
show
Accessing conn on the interface Dazzle\Socket\SocketInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
146
        }
147 1
        catch (Error $ex)
148
        {
149
            $this->handleError($socket, $ex);
150
        }
151 1
        catch (Exception $ex)
152
        {
153 1
            $this->handleError($socket, $ex);
154
        }
155 6
    }
156
157
    /**
158
     * Handler triggered when an error has occured during doing operation on existing connection.
159
     *
160
     * @param SocketInterface $socket
161
     * @param Error|Exception $ex
162
     */
163 2 View Code Duplication
    public function handleError($socket, $ex)
0 ignored issues
show
The parameter $ex 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...
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...
164
    {
165
        try
166
        {
167 2
            $this->component->handleError($socket->conn, $ex);
0 ignored issues
show
Accessing conn on the interface Dazzle\Socket\SocketInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
168
        }
169 1
        catch (Error $ex)
170
        {
171
            $this->close($socket);
172
        }
173 1
        catch (Exception $ex)
174
        {
175 1
            $this->close($socket);
176
        }
177 2
    }
178
179
    /**
180
     * Close socket.
181
     *
182
     * @param SocketInterface $socket
183
     */
184 1
    protected function close(SocketInterface $socket)
185
    {
186 1
        $socket->close();
187 1
    }
188
}
189