Issues (39)

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/Centrifugo.php (1 issue)

Labels
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
 * This file is part of the FreshCentrifugoBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CentrifugoBundle\Service;
14
15
use Fresh\CentrifugoBundle\Logger\CommandHistoryLogger;
16
use Fresh\CentrifugoBundle\Model;
17
use Fresh\CentrifugoBundle\Model\CommandInterface;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpKernel\Profiler\Profiler;
20
use Symfony\Contracts\HttpClient\HttpClientInterface;
21
22
/**
23
 * Centrifugo.
24
 *
25
 * @author Artem Henvald <[email protected]>
26
 */
27
class Centrifugo implements CentrifugoInterface
28
{
29
    private string $endpoint;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
30
    private string $apiKey;
31
    private HttpClientInterface $httpClient;
32
    private ResponseProcessor $responseProcessor;
33
    private CommandHistoryLogger $commandHistoryLogger;
34
    private CentrifugoChecker $centrifugoChecker;
35
    private bool $profilerEnabled;
36
37
    /**
38
     * @param string               $endpoint
39
     * @param string               $apiKey
40
     * @param HttpClientInterface  $httpClient
41
     * @param ResponseProcessor    $responseProcessor
42
     * @param CommandHistoryLogger $commandHistoryLogger
43
     * @param CentrifugoChecker    $centrifugoChecker
44
     * @param Profiler|null        $profiler
45
     */
46
    public function __construct(string $endpoint, string $apiKey, HttpClientInterface $httpClient, ResponseProcessor $responseProcessor, CommandHistoryLogger $commandHistoryLogger, CentrifugoChecker $centrifugoChecker, ?Profiler $profiler)
47
    {
48
        $this->endpoint = $endpoint;
49
        $this->apiKey = $apiKey;
50
        $this->httpClient = $httpClient;
51
        $this->responseProcessor = $responseProcessor;
52
        $this->commandHistoryLogger = $commandHistoryLogger;
53
        $this->centrifugoChecker = $centrifugoChecker;
54
        $this->profilerEnabled = $profiler instanceof Profiler;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function publish(array $data, string $channel): void
61
    {
62
        $this->doSendCommand(new Model\PublishCommand($data, $channel));
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function broadcast(array $data, array $channels): void
69
    {
70
        $this->doSendCommand(new Model\BroadcastCommand($data, $channels));
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function unsubscribe(string $user, string $channel): void
77
    {
78
        $this->doSendCommand(new Model\UnsubscribeCommand($user, $channel));
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function disconnect(string $user): void
85
    {
86
        $this->doSendCommand(new Model\DisconnectCommand($user));
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function presence(string $channel): array
93
    {
94
        return (array) $this->doSendCommand(new Model\PresenceCommand($channel));
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function presenceStats(string $channel): array
101
    {
102
        return (array) $this->doSendCommand(new Model\PresenceStatsCommand($channel));
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function history(string $channel): array
109
    {
110
        return (array) $this->doSendCommand(new Model\HistoryCommand($channel));
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function historyRemove(string $channel): void
117
    {
118
        $this->doSendCommand(new Model\HistoryRemoveCommand($channel));
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function channels(): array
125
    {
126
        return (array) $this->doSendCommand(new Model\ChannelsCommand());
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function info(): array
133
    {
134
        return (array) $this->doSendCommand(new Model\InfoCommand());
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function batchRequest(array $commands): array
141
    {
142
        return (array) $this->doSendCommand(new Model\BatchRequest($commands));
143
    }
144
145
    /**
146
     * @param CommandInterface $command
147
     *
148
     * @return array|null
149
     */
150
    private function doSendCommand(CommandInterface $command): ?array
151
    {
152
        foreach ($command->getChannels() as $channel) {
153
            $this->centrifugoChecker->assertValidChannelName($channel);
154
        }
155
156
        if ($command instanceof Model\BatchRequest) {
157
            $json = $command->prepareLineDelimitedJson();
158
        } else {
159
            $json = \json_encode($command, \JSON_THROW_ON_ERROR);
160
        }
161
162
        if ($this->profilerEnabled) {
163
            $this->commandHistoryLogger->increaseRequestsCount();
164
        }
165
166
        $response = $this->httpClient->request(
167
            Request::METHOD_POST,
168
            $this->endpoint,
169
            [
170
                'headers' => [
171
                    'Authorization' => 'apikey '.$this->apiKey,
172
                    'Content-Type' => 'application/json',
173
                ],
174
                'body' => $json,
175
            ]
176
        );
177
178
        return $this->responseProcessor->processResponse($command, $response);
179
    }
180
}
181