Issues (33)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/AMQPConnection.php (1 issue)

1
<?php
2
3
namespace NeedleProject\LaravelRabbitMq;
4
5
use PhpAmqpLib\Channel\AMQPChannel;
6
use PhpAmqpLib\Connection\AbstractConnection;
7
use PhpAmqpLib\Connection\AMQPConnectionConfig;
8
use PhpAmqpLib\Connection\AMQPConnectionFactory;
9
use PhpAmqpLib\Connection\AMQPSocketConnection;
10
use PhpAmqpLib\Connection\AMQPStreamConnection;
11
12
/**
13
 * Class AMQPConnection
14
 *
15
 * @package NeedleProject\LaravelRabbitMq
16
 * @author  Adrian Tilita <[email protected]>
17
 */
18
class AMQPConnection
19
{
20
    /**
21
     * @const array Default connections parameters
22
     */
23
    const DEFAULTS = [
24
        'hostname' => '127.0.0.1',
25
        'port' => 5672,
26
        'username' => 'guest',
27
        'password' => 'guest',
28
        'vhost' => '/',
29
30
        # whether the connection should be lazy
31
        'lazy' => true,
32
33
        'insist' => false,
34
35
        # More info about timeouts can be found on https://www.rabbitmq.com/networking.html
36
        'read_write_timeout' => 3,   // default timeout for writing/reading (in seconds)
37
        'connect_timeout' => 3,
38
        'channel_rpc_timeout' => 0,
39
        'heartbeat' => 0,
40
        'keep_alive' => false,
41
42
        'connection_name' => '',
43
44
        'io_type' => AMQPConnectionConfig::IO_TYPE_STREAM,
45
46
        'secure' => false,
47
        'ssl_crypto_method' => STREAM_CRYPTO_METHOD_ANY_CLIENT,
48
        'ssl_verify' => false,
49
        'ssl_verify_name' => false,
50
51
        'locale' => 'en_US',
52
53
        'login_method' => AMQPConnectionConfig::AUTH_AMQPPLAIN,
54
        'login_response' => null,
55
    ];
56
57
    /**
58
     * @var array
59
     */
60
    protected array $connectionDetails = [];
61
62
    /**
63
     * @var string
64
     */
65
    protected string $aliasName = '';
66
67
    /**
68
     * @var null|AbstractConnection
69
     */
70
    private ?AbstractConnection $connection = null;
71
72
    /**
73
     * @var null|AMQPChannel
74
     */
75
    private ?AMQPChannel $channel = null;
76
77
    /**
78
     * @param string $aliasName
79
     * @param array $connectionDetails
80
     * @return AMQPConnection
81
     */
82
    public static function createConnection(string $aliasName, array $connectionDetails)
83
    {
84
        if ($diff = array_diff(array_keys($connectionDetails), array_keys(self::DEFAULTS))) {
85
            throw new \InvalidArgumentException(
86
                sprintf(
87
                    "Cannot create connection %s, received unknown arguments: %s!",
88
                    (string) $aliasName,
89
                    implode(', ', $diff)
90
                )
91
            );
92
        }
93
94
        return new static(
95
            $aliasName,
96
            array_merge(self::DEFAULTS, $connectionDetails)
97
        );
98
    }
99
100
    /**
101
     * AMQPConnection constructor.
102
     *
103
     * @param string $aliasName
104
     * @param array $connectionDetails
105
     */
106
    public function __construct(string $aliasName, array $connectionDetails = [])
107
    {
108
        $this->aliasName = $aliasName;
109
        $this->connectionDetails = $connectionDetails;
110
111
        if (isset($connectionDetails['lazy']) && $connectionDetails['lazy'] === false) {
112
            // dummy call
113
            $this->getConnection();
114
        }
115
    }
116
117
    /**
118
     * @return AbstractConnection
119
     */
120
    protected function getConnection(): AbstractConnection
121
    {
122
        if (is_null($this->connection)) {
123
            $this->connection = $this->createConnectionByType();
124
        }
125
126
        return $this->connection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->connection could return the type null which is incompatible with the type-hinted return PhpAmqpLib\Connection\AbstractConnection. Consider adding an additional type-check to rule them out.
Loading history...
127
    }
128
129
    private function createConnectionByType(): AbstractConnection
130
    {
131
        $config = new AMQPConnectionConfig();
132
133
        $config->setHost($this->connectionDetails['hostname']);
134
        $config->setPort($this->connectionDetails['port']);
135
        $config->setUser($this->connectionDetails['username']);
136
        $config->setPassword($this->connectionDetails['password']);
137
        $config->setVhost($this->connectionDetails['vhost']);
138
139
        if (!empty($this->connectionDetails['io_type'])) {
140
            $config->setIoType($this->connectionDetails['io_type']);
141
        }
142
143
        if (!empty($this->connectionDetails['connection_name'])) {
144
            $config->setConnectionName($this->connectionDetails['connection_name']);
145
        }
146
147
        if (isset($this->connectionDetails['connect_timeout'])) {
148
            $config->setConnectionTimeout((float)$this->connectionDetails['connect_timeout']);
149
        }
150
151
        if (isset($this->connectionDetails['read_write_timeout'])) {
152
            $config->setReadTimeout((float)$this->connectionDetails['read_write_timeout']);
153
            $config->setWriteTimeout((float)$this->connectionDetails['read_write_timeout']);
154
155
        }
156
157
        if (isset($this->connectionDetails['channel_rpc_timeout'])) {
158
            $config->setChannelRPCTimeout((float)$this->connectionDetails['channel_rpc_timeout']);
159
        }
160
161
        if (isset($this->connectionDetails['keep_alive'])) {
162
            $config->setKeepalive((bool)$this->connectionDetails['keep_alive']);
163
        }
164
165
        if (isset($this->connectionDetails['heartbeat'])) {
166
            $config->setHeartbeat((int)$this->connectionDetails['heartbeat']);
167
        }
168
169
        if (isset($this->connectionDetails['secure'])) {
170
            $config->setIsSecure((bool)$this->connectionDetails['secure']);
171
        }
172
173
        if (isset($this->connectionDetails['ssl_crypto_method'])) {
174
            $config->setSslCryptoMethod($this->connectionDetails['ssl_crypto_method']);
175
        }
176
177
        if (isset($this->connectionDetails['ssl_verify_name'])) {
178
            $config->setSslVerifyName((bool)$this->connectionDetails['ssl_verify_name']);
179
        }
180
181
        if (isset($this->connectionDetails['ssl_verify'])) {
182
            $config->setSslVerify((bool)$this->connectionDetails['ssl_verify']);
183
        }
184
185
        if (isset($this->connectionDetails['lazy'])) {
186
            $config->setIsLazy((bool)$this->connectionDetails['lazy']);
187
        }
188
189
        if (isset($this->connectionDetails['insist'])) {
190
            $config->setInsist((bool)$this->connectionDetails['insist']);
191
        }
192
193
        if (!empty($this->connectionDetails['locale'])) {
194
            $config->setLocale($this->connectionDetails['locale']);
195
        }
196
197
        if (!empty($this->connectionDetails['login_response'])) {
198
            $config->setLoginResponse($this->connectionDetails['login_response']);
199
        }
200
201
        return AMQPConnectionFactory::create($config);
202
    }
203
204
    /**
205
     * Reconnect
206
     */
207
    public function reconnect(): void
208
    {
209
        $this->getConnection()->channel()->close();
210
        $this->channel = null;
211
        $this->getConnection()->reconnect();
212
    }
213
214
215
    public function getChannel(): ?AMQPChannel
216
    {
217
        if (is_null($this->channel)) {
218
            $this->channel = $this->getConnection()->channel();
219
        }
220
221
        return $this->channel;
222
    }
223
224
    /**
225
     * Retrieve the connection alias name
226
     *
227
     * @return string
228
     */
229
    public function getAliasName(): string
230
    {
231
        return $this->aliasName;
232
    }
233
}
234