Issues (20)

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.

Service/Worker.php (3 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 SfCod\SocketIoBundle\Service;
4
5
use Predis\Connection\ConnectionException;
6
use Symfony\Component\Console\Style\SymfonyStyle;
7
use Symfony\Component\Process\Process;
0 ignored issues
show
This use statement conflicts with another class in this namespace, SfCod\SocketIoBundle\Service\Process.

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
9
/**
10
 * Class Worker.
11
 *
12
 * @author Virchenko Maksim <[email protected]>
13
 *
14
 * @package SfCod\SocketIoBundle\Service
15
 */
16
class Worker
17
{
18
    /**
19
     * @var EventManager
20
     */
21
    private $eventManager;
22
23
    /**
24
     * @var RedisDriver
25
     */
26
    private $redisDriver;
27
28
    /**
29
     * @var Broadcast
30
     */
31
    private $broadcast;
32
33
    /**
34
     * @var string
35
     */
36
    private $logDir;
37
38
    /**
39
     * Worker constructor.
40
     */
41
    public function __construct(EventManager $eventManager, RedisDriver $redisDriver, Broadcast $broadcast, string $logDir)
42
    {
43
        $this->eventManager = $eventManager;
44
        $this->redisDriver = $redisDriver;
45
        $this->broadcast = $broadcast;
46
        $this->logDir = $logDir;
47
    }
48
49
    /**
50
     * Get node js process.
51
     */
52
    public function nodeJs(string $server, string $ssl = ''): Process
53
    {
54
        $cmd = sprintf('node %s/%s', realpath(dirname(__FILE__) . '/../Server'), 'index.js');
55
56
        $connection = json_encode(array_filter([
57
            'host' => $this->redisDriver->getHost(),
58
            'port' => $this->redisDriver->getPort(),
59
            'password' => $this->redisDriver->getPassword(),
60
        ]));
61
62
        $args = array_filter([
63
            'server' => $server,
64
            'pub' => $connection,
65
            'sub' => $connection,
66
            'channels' => implode(',', $this->broadcast->channels()),
67
            'nsp' => getenv('SOCKET_IO_NSP'),
68
            'ssl' => empty($ssl) ? null : $ssl,
69
            'runtime' => $this->logDir,
70
        ], 'strlen');
71
        foreach ($args as $key => $value) {
72
            $cmd .= ' -' . $key . '=\'' . $value . '\'';
73
        }
74
75
        $process = new Process($cmd);
0 ignored issues
show
$cmd is of type string, but the function expects a array.

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...
76
77
        return $process;
78
    }
79
80
    /**
81
     * Start predis.
82
     */
83
    public function predis(SymfonyStyle $io)
84
    {
85
        $pubSubLoop = function () use ($io) {
86
            /** @var \Predis\Client $client */
87
            $client = $this->redisDriver->getClient(true);
88
89
            // Initialize a new pubsub consumer.
90
            $pubSub = $client->pubSubLoop();
91
92
            $channels = [];
93
            foreach ($this->broadcast->channels() as $key => $channel) {
94
                $channels[$key] = $channel . '.io';
95
            }
96
97
            // Subscribe to your channels
98
            $pubSub->subscribe(array_merge(['control_channel'], $channels));
99
100
            // Start processing the pubsup messages. Open a terminal and use redis-cli
101
            // to push messages to the channels. Examples:
102
            //   ./redis-cli PUBLISH notifications "this is a test"
103
            //   ./redis-cli PUBLISH control_channel quit_loop
104
            foreach ($pubSub as $message) {
0 ignored issues
show
The expression $pubSub of type object<Predis\PubSub\Consumer>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
105
                switch ($message->kind) {
106
                    case 'subscribe':
107
                        $io->success("Subscribed to {$message->channel}");
108
                        break;
109
                    case 'message':
110
                        if ('control_channel' == $message->channel) {
111
                            if ('quit_loop' == $message->payload) {
112
                                $io->success("Aborting pubsub loop...\n");
113
                                $pubSub->unsubscribe();
114
                            } else {
115
                                $io->success("Received an unrecognized command: {$message->payload}\n");
116
                            }
117
                        } else {
118
                            $payload = json_decode($message->payload, true);
119
                            $data = $payload['data'] ?? [];
120
121
                            $this->broadcast->on($payload['name'], $data);
122
                        }
123
                        break;
124
                }
125
            }
126
127
            // Always unset the pubsub consumer instance when you are done! The
128
            // class destructor will take care of cleanups and prevent protocol
129
            // desynchronizations between the client and the server.
130
            unset($pubSub);
131
        };
132
133
        // Auto recconnect on redis timeout
134
        try {
135
            $pubSubLoop();
136
        } catch (ConnectionException $e) {
137
            $pubSubLoop();
138
        }
139
    }
140
}
141