Issues (90)

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/Chat.php (21 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
 * Chat Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
15
use Ratchet\MessageComponentInterface;
16
use Ratchet\ConnectionInterface;
17
// use ChatApp\Models\Message;
18
use ChatApp\Reply;
19
use ChatApp\Conversation;
20
use ChatApp\Receiver;
21
use ChatApp\SideBar;
22
use ChatApp\Search;
23
use ChatApp\Compose;
24
use ChatApp\Online;
25
26
/**
27
 * This Class handles the all the main functionalities for this ChatApp.
28
 *
29
 * @category PHP
30
 * @package  OpenChat
31
 * @author   Ankit Jain <[email protected]>
32
 * @license  The MIT License (MIT)
33
 * @link     https://github.com/ankitjain28may/openchat
34
 */
35
36
class Chat implements MessageComponentInterface
37
{
38
    /*
39
    |--------------------------------------------------------------------------
40
    | Chat Class
41
    |--------------------------------------------------------------------------
42
    |
43
    | This Class handles the all the main functionalities for this ChatApp.
44
    |
45
    */
46
47
    protected $clients;
48
49
    /**
50
     * Create a new class instance.
51
     *
52
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
53
     */
54
    public function __construct()
55
    {
56
        $this->clients = new \SplObjectStorage;
57
    }
58
59
    /**
60
     * Open the Socket Connection and get client connection
61
     *
62
     * @param ConnectionInterface $conn To store client details
63
     *
64
     * @return void
65
     */
66
    public function onOpen(ConnectionInterface $conn)
67
    {
68
        $conn = $this->setID($conn);
69
        $this->clients->attach($conn);
70
        echo "New connection! ({$conn->resourceId})\n";
0 ignored issues
show
Accessing resourceId on the interface Ratchet\ConnectionInterface 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...
71
        Online::setOnlineStatus($conn->userId);
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
72
    }
73
74
    /**
75
     * Set Session Id in Connection object
76
     *
77
     * @param ConnectionInterface $conn To store client details
78
     *
79
     * @return $conn
0 ignored issues
show
The doc-type $conn could not be parsed: Unknown type name "$conn" at position 0. (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...
80
     */
81
    public function setID($conn)
82
    {
83
        session_id($conn->WebSocket->request->getCookies()['PHPSESSID']);
0 ignored issues
show
Accessing WebSocket on the interface Ratchet\ConnectionInterface 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...
84
        @session_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
85
        $conn->userId = $_SESSION['start'];
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
86
        session_write_close();
87
        return $conn;
88
    }
89
90
    /**
91
     * Send Messages to Clients
92
     *
93
     * @param ConnectionInterface $from To store client details
94
     * @param string              $msg  To store message
95
     *
96
     * @return void
97
     */
98
    public function onMessage(ConnectionInterface $from, $msg)
99
    {
100
        $msg = (object)json_decode($msg);
101
        if ($msg->type == 'OpenChat initiated..!') {
102
            $initial = (object)array();
103
            $initial->initial = json_decode($this->onSidebar($from->userId));
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
104
105
            if ($initial->initial != null) {
106
                $initial->conversation = json_decode(
107
                    $this->onConversation(
108
                        json_encode(
109
                            [
110
                            "details" => $initial->initial[0]->login_id,
111
                            "load" => 20,
112
                            "userId" => $from->userId
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
113
                            ]
114
                        ), true
115
                    )
116
                );
117
            }
118
            $from->send(json_encode($initial));
119
        } else if ($msg->type == 'Load Sidebar') {
120
            $sidebar = (object)array();
121
            $sidebar->sidebar = json_decode($this->onSidebar($from->userId));
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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
            $from->send(json_encode($sidebar));
123
        } else if ($msg->type == 'Initiated') {
124
            $msg->userId = $from->userId;
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
125
            $result = (object)array();
126
            $result->conversation = json_decode(
127
                $this->onConversation(json_encode($msg), false)
128
            );
129
            $from->send(json_encode($result));
130
        } else if ($msg->type == 'Search') {
131
            $msg->userId = $from->userId;
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
132
            $searchResult = $this->onSearch($msg);
133
            $from->send($searchResult);
134
        } else if ($msg->type == 'Compose') {
135
            $msg->userId = $from->userId;
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
136
            $composeResult = $this->onCompose($msg);
137
            $from->send($composeResult);
138
        } else {
139
            $msg->userId = $from->userId;
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
140
            $msg->name = convert_uudecode(hex2bin($msg->name));
141
142
            $getReturn = $this->onReply($msg);
143
            echo $getReturn;
144
145
            $receiveResult = (object)array();
146
            $sentResult = (object)array();
147
            foreach ($this->clients as $client) {
148
                if ($client->userId == $msg->name) {
149
                    $receiveResult->sidebar = json_decode(
150
                        $this->onSidebar($client->userId)
151
                    );
152
153
                    $receiveResult->reply = json_decode(
154
                        $this->onReceiver(
155
                            json_encode(
156
                                [
157
                                "details" => $client->userId,
158
                                "load" => 20,
159
                                "userId" => $from->userId
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
160
                                ]
161
                            ), true
162
                        )
163
                    );
164
165
                    $client->send(json_encode($receiveResult));
166
                } else if ($client == $from) {
167
                    $sentResult->sidebar = json_decode(
168
                        $this->onSidebar($client->userId)
169
                    );
170
171
                    $sentResult->conversation = json_decode(
172
                        $this->onConversation(
173
                            json_encode(
174
                                [
175
                                "details" => bin2hex(convert_uuencode($msg->name)),
176
                                "load" => 20,
177
                                "userId" => $from->userId
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
178
                                ]
179
                            ), true
180
                        )
181
                    );
182
                    $client->send(json_encode($sentResult));
183
                }
184
            }
185
186
        }
187
    }
188
189
    /**
190
     * To Call SideBar Class
191
     *
192
     * @param string $data To store data
193
     *
194
     * @return string
195
     */
196
    public function onSidebar($data)
197
    {
198
        $obSidebar = new SideBar();
199
        return $obSidebar->loadSideBar($data);
200
    }
201
202
    /**
203
     * To Call Conversation Class
204
     *
205
     * @param string  $data to store data
206
     * @param boolean $para to store True/False
207
     *
208
     * @return string
209
     */
210
    public function onConversation($data, $para)
211
    {
212
        $obConversation = new Conversation();
213
        return $obConversation->conversationLoad($data, $para);
214
    }
215
216
    /**
217
     * To Call Receiver Class
218
     *
219
     * @param string  $data to store data
220
     * @param boolean $para to store True/False
221
     *
222
     * @return string
223
     */
224
    public function onReceiver($data, $para)
225
    {
226
        $obReceiver = new Receiver();
227
        return $obReceiver->receiverLoad($data, $para);
228
    }
229
230
    /**
231
     * To Call Search Class
232
     *
233
     * @param string $data to store data
234
     *
235
     * @return string
236
     */
237
    public function onSearch($data)
238
    {
239
        $obSearch = new Search();
240
        return $obSearch->searchItem($data);
0 ignored issues
show
$data is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
241
    }
242
243
    /**
244
     * To Call Compose Class
245
     *
246
     * @param string $data to store data
247
     *
248
     * @return string
249
     */
250
    public function onCompose($data)
251
    {
252
        $obCompose = new Compose();
253
        return $obCompose->selectUser($data);
0 ignored issues
show
$data is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
254
    }
255
256
    /**
257
     * To Call Reply Class
258
     *
259
     * @param string $data to store data
260
     *
261
     * @return string
262
     */
263
    public function onReply($data)
264
    {
265
        $obReply = new Reply();
266
        return $obReply->replyTo($data);
0 ignored issues
show
$data is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
267
    }
268
269
    /**
270
     * To Call Online Class
271
     *
272
     * @param ConnectionInterface $conn To store client details
273
     *
274
     * @return void
275
     */
276
    public function onClose(ConnectionInterface $conn)
277
    {
278
        Online::removeOnlineStatus($conn->userId);
0 ignored issues
show
Accessing userId on the interface Ratchet\ConnectionInterface 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...
279
        $this->clients->detach($conn);
280
        echo "Connection {$conn->resourceId} has disconnected\n";
0 ignored issues
show
Accessing resourceId on the interface Ratchet\ConnectionInterface 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...
281
    }
282
283
    /**
284
     * To Show error due to any problem occured
285
     *
286
     * @param ConnectionInterface $conn To store client details
287
     * @param \Exception          $e    To store exception
288
     *
289
     * @return void
290
     */
291
    public function onError(ConnectionInterface $conn, \Exception $e)
292
    {
293
        echo "An error has occurred: {$e->getMessage()}\n";
294
        $conn->close();
295
    }
296
297
}
298