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.

DependencyInjection/SocketIoExtension.php (5 issues)

Severity

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\DependencyInjection;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Psr\Log\LoggerInterface;
7
use SfCod\SocketIoBundle\Command\NodeJsServerCommand;
8
use SfCod\SocketIoBundle\Command\PhpServerCommand;
9
use SfCod\SocketIoBundle\Command\ProcessCommand;
10
use SfCod\SocketIoBundle\Events\EventInterface;
11
use SfCod\SocketIoBundle\Events\EventPublisherInterface;
12
use SfCod\SocketIoBundle\Events\EventSubscriberInterface;
13
use SfCod\SocketIoBundle\Middleware\Process\DoctrineReconnect;
14
use SfCod\SocketIoBundle\Service\Broadcast;
15
use SfCod\SocketIoBundle\Service\EventManager;
16
use SfCod\SocketIoBundle\Service\JoinHandler;
17
use SfCod\SocketIoBundle\Service\LeaveHandler;
18
use SfCod\SocketIoBundle\Service\Process;
19
use SfCod\SocketIoBundle\Service\RedisDriver;
20
use SfCod\SocketIoBundle\Service\Worker;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Definition;
23
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
24
use Symfony\Component\DependencyInjection\Extension\Extension;
25
use Symfony\Component\DependencyInjection\Reference;
26
27
/**
28
 * Class SocketIoExtension.
29
 *
30
 * @author Virchenko Maksim <[email protected]>
31
 *
32
 * @package SfCod\SocketIoBundle\DependencyInjection
33
 */
34
class SocketIoExtension extends Extension
35
{
36
    /**
37
     * Loads a specific configuration.
38
     *
39
     * @throws \Exception
40
     */
41
    public function load(array $configs, ContainerBuilder $container)
42
    {
43
        $configuration = new SocketIoConfiguration();
44
45
        $config = $this->processConfiguration($configuration, $configs);
46
47
        $container->registerForAutoconfiguration(EventPublisherInterface::class)
48
            ->addTag('socketio.publisher');
49
        $container->registerForAutoconfiguration(EventSubscriberInterface::class)
50
            ->addTag('socketio.subscriber');
51
        $container->registerForAutoconfiguration(EventInterface::class)
52
            ->addTag('socketio.events');
53
54
        $this->createDriver($config, $container);
55
        $this->createBroadcast($config, $container);
56
        $this->createEventManager($config, $container);
57
        $this->createProcess($config, $container);
58
        $this->createWorker($config, $container);
59
        $this->createCommands($config, $container);
60
        $this->createHandlers($config, $container);
61
62
        $eventManager = $container->get(EventManager::class);
63
64
        foreach ($eventManager->getList() as $name => $class) {
65
            $definition = new Definition($class);
66
            $definition
67
                ->setAutowired(true)
68
                ->setAutoconfigured(true)
69
                ->setPublic(false);
70
            $eventManager->addMethodCall('addEvent', [$definition]);
71
        }
72
    }
73
74
    /**
75
     * Create driver.
76
     */
77
    private function createDriver(array $config, ContainerBuilder $container)
0 ignored issues
show
The parameter $config 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...
78
    {
79
        $redis = new Definition(RedisDriver::class);
80
        $redis->setArguments([
81
            $container->getParameter('env(REDIS_URL)'),
82
        ]);
83
84
        $container->setDefinition(RedisDriver::class, $redis);
85
    }
86
87
    /**
88
     * Create broadcast.
89
     */
90
    private function createBroadcast(array $config, ContainerBuilder $container)
91
    {
92
        $broadcast = new Definition(Broadcast::class);
93
        $broadcast->setArguments([
94
            new Reference(RedisDriver::class),
95
            new Reference(EventManager::class),
96
            new Reference(LoggerInterface::class),
97
            new Reference(Process::class),
98
        ]);
99
100
        if ($container->getParameter('kernel.bundles')['DoctrineBundle'] ?? null) {
101
            $doctrineReconnect = new Definition(DoctrineReconnect::class);
102
            $doctrineReconnect->setArguments([
103
                new Reference(EntityManagerInterface::class),
104
            ]);
105
106
            $container->setDefinition(DoctrineReconnect::class, $doctrineReconnect);
107
        }
108
109
        if (isset($config['processMiddlewares'])) {
110
            $processMiddlewares = [];
111
            foreach ($config['processMiddlewares'] as $processMiddlewareId) {
112
                if (!$container->has($processMiddlewareId)) {
113
                    throw new RuntimeException(sprintf('Invalid middleware: service "%s" not found.', $processMiddlewareId));
114
                }
115
                $processMiddlewares[] = new Reference($processMiddlewareId);
116
            }
117
118
            $broadcast->addMethodCall('setProcessMiddlewares', [$processMiddlewares]);
119
        }
120
121
        $container->setDefinition(Broadcast::class, $broadcast);
122
    }
123
124
    /**
125
     * Create event manager.
126
     */
127
    private function createEventManager(array $config, ContainerBuilder $container)
128
    {
129
        $eventManager = new Definition(EventManager::class);
130
        $eventManager->setArguments([
131
            $container->getParameter('kernel.root_dir'),
132
            $config['namespaces'],
133
        ]);
134
135
        $container->setDefinition(EventManager::class, $eventManager);
136
    }
137
138
    /**
139
     * Create process.
140
     */
141
    private function createProcess(array $config, ContainerBuilder $container)
0 ignored issues
show
The parameter $config 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...
142
    {
143
        $jobProcess = new Definition(Process::class);
144
        $jobProcess->setArguments([
145
            'console',
146
            sprintf('%s/bin', $container->getParameter('kernel.project_dir')),
147
        ]);
148
149
        $container->setDefinition(Process::class, $jobProcess);
150
    }
151
152
    /**
153
     * Create worker.
154
     *
155
     * @throws \Exception
156
     */
157
    private function createWorker(array $config, ContainerBuilder $container)
0 ignored issues
show
The parameter $config 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...
158
    {
159
        $worker = new Definition(Worker::class);
160
        $worker->setArguments([
161
            new Reference(EventManager::class),
162
            new Reference(RedisDriver::class),
163
            new Reference(Broadcast::class),
164
            $container->hasParameter('kernel.logs_dir') ?
165
                $container->getParameter('kernel.logs_dir') . '/socketio' :
166
                $container->getParameter('kernel.root_dir') . '/../../var/log/socketio',
167
        ]);
168
169
        $container->setDefinition(Worker::class, $worker);
170
    }
171
172
    /**
173
     * Create handlers.
174
     *
175
     * @throws \Exception
176
     */
177
    private function createHandlers(array $config, ContainerBuilder $container)
0 ignored issues
show
The parameter $config 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...
178
    {
179
        $joinHandler = new Definition(JoinHandler::class);
180
        $joinHandler->setArguments([
181
            new Reference(Broadcast::class),
182
            new Reference(LoggerInterface::class),
183
        ]);
184
        $joinHandler->addTag('sfcod.socketio.event');
185
        $container->setDefinition(JoinHandler::class, $joinHandler);
186
187
        $leaveHandler = new Definition(LeaveHandler::class);
188
        $leaveHandler->setArguments([
189
            new Reference(Broadcast::class),
190
            new Reference(LoggerInterface::class),
191
        ]);
192
        $leaveHandler->addTag('sfcod.socketio.event');
193
        $container->setDefinition(LeaveHandler::class, $leaveHandler);
194
    }
195
196
    /**
197
     * Create command.
198
     */
199
    private function createCommands(array $config, ContainerBuilder $container)
0 ignored issues
show
The parameter $config 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...
200
    {
201
        $nodeJs = new Definition(NodeJsServerCommand::class);
202
        $nodeJs->setArguments([
203
            new Reference(Worker::class),
204
        ]);
205
        $nodeJs->addTag('console.command');
206
207
        $phpServer = new Definition(PhpServerCommand::class);
208
        $phpServer->setArguments([
209
            new Reference(Worker::class),
210
        ]);
211
        $phpServer->addTag('console.command');
212
213
        $process = new Definition(ProcessCommand::class);
214
        $process->setArguments([
215
            new Reference(Broadcast::class),
216
        ]);
217
        $process->addTag('console.command');
218
219
        $container->addDefinitions([
220
            PhpServerCommand::class => $phpServer,
221
            ProcessCommand::class => $process,
222
            NodeJsServerCommand::class => $nodeJs,
223
        ]);
224
    }
225
226
    /**
227
     * Get extension alias.
228
     *
229
     * @return string
230
     */
231
    public function getAlias()
232
    {
233
        return 'sfcod_socketio';
234
    }
235
}
236