Issues (80)

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.

Queue/Queue.php (1 issue)

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 Cmobi\RabbitmqBundle\Queue;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnection;
7
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
8
use Cmobi\RabbitmqBundle\Connection\Exception\InvalidAMQPChannelException;
9
use Psr\Log\LoggerInterface;
10
11
class Queue implements QueueInterface
12
{
13
    private $connectionManager;
14
    private $connection;
15
    private $connectionName;
16
    private $channel;
17
    private $queueBag;
18
    private $errOutput;
19
    private $logOutput;
20
    private $callback;
21
22
    public function __construct(
23
        ConnectionManager $connectionManager,
24
        QueueBagInterface $queueBag,
25
        $connectionName = 'default',
26
        QueueCallbackInterface $callback = null
27
    )
28
    {
29
        $this->connectionManager = $connectionManager;
30
        $this->connectionName = $connectionName;
31
        $this->connection = $this->getConnectionManager()->getConnection($connectionName);
32
        $this->queueBag = $queueBag;
33
        $this->errOutput = fopen('php://stderr', 'a+');
34
        $this->logOutput = fopen('php://stdout', 'a+');
35
        $this->callback = $callback;
36
    }
37
38
    /**
39
     * @return CmobiAMQPChannel
40
     *
41
     * @throws InvalidAMQPChannelException
42
     */
43
    protected function getChannel()
44
    {
45
        if ($this->channel instanceof CmobiAMQPChannel) {
46
            return $this->channel;
47
        }
48
        $this->channel = $this->getConnection()->channel();
49
50
        if (!$this->channel instanceof CmobiAMQPChannel) {
51
            throw new InvalidAMQPChannelException('Failed get AMQPChannel');
52
        }
53
54
        return $this->channel;
55
    }
56
57
    protected function createQueue()
58
    {
59
        $queueBag = $this->getQueuebag();
60
61
        $this->getChannel()->basic_qos(null, $queueBag->getBasicQos(), null);
0 ignored issues
show
null is of type null, but the function expects a boolean.

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...
62
63
        if ($queueBag->getExchangeDeclare()) {
64
            $this->getChannel()->exchangeDeclare($queueBag->getExchangeDeclare());
65
            list($queueName) = $this->getChannel()->queueDeclare($queueBag->getQueueDeclare());
66
            $this->getChannel()->queue_bind($queueName, $queueBag->getExchange());
67
        } else {
68
            $this->getChannel()->queueDeclare($queueBag->getQueueDeclare());
69
        }
70
        $this->getChannel()->basicConsume($queueBag->getQueueConsume(), $this->getCallback()->toClosure());
71
    }
72
73
    /**
74
     * Declare and start queue in broker.
75
     */
76
    public function start()
77
    {
78
        $this->createQueue();
79
80
        while (count($this->getChannel()->callbacks)) {
81
            try {
82
                $this->getChannel()->wait();
83
            } catch (\Exception $e) {
84
                fwrite($this->errOutput, $e->getMessage());
85
                $this->forceReconnect();
86
87
                continue;
88
            }
89
        }
90
        $connection = $this->getChannel()->getConnection();
91
        $this->getChannel()->close();
92
        $connection->close();
93
    }
94
95
    /**
96
     * @return QueueBagInterface
97
     */
98
    public function getQueuebag()
99
    {
100
        return $this->queueBag;
101
    }
102
103
    /**
104
     * @param QueueCallbackInterface $callback
105
     */
106
    public function setCallback(QueueCallbackInterface $callback)
107
    {
108
        $this->callback = $callback;
109
    }
110
111
    /**
112
     * @return QueueCallbackInterface
113
     */
114
    public function getCallback()
115
    {
116
        return $this->callback;
117
    }
118
119
    /**
120
     * @return ConnectionManager
121
     */
122
    public function getConnectionManager()
123
    {
124
        return $this->connectionManager;
125
    }
126
127
    /**
128
     * @return CmobiAMQPConnection
129
     */
130
    public function getConnection()
131
    {
132
        return $this->connection;
133
    }
134
135
    /**
136
     * Retry connect to message broker until it can.
137
     */
138
    /**
139
     * @param CmobiAMQPConnection|null $connection
140
     *
141
     * @return CmobiAMQPChannel
142
     */
143
    public function forceReconnect(CmobiAMQPConnection $connection = null)
144
    {
145
        do {
146
            try {
147
                $failed = false;
148
                fwrite($this->logOutput, 'start Queue::forceReconnect() - trying connect...' . PHP_EOL);
149
                $this->connection = $this->getConnectionManager()->getConnection($this->connectionName);
150
                $this->channel = $this->getConnection()->channel();
151
                $this->createQueue();
152
            } catch (\Exception $e) {
153
                $failed = true;
154
                sleep(3);
155
                fwrite($this->errOutput, 'failed Queue::forceReconnect() - ' . $e->getMessage() . PHP_EOL);
156
            }
157
        } while ($failed);
158
        fwrite($this->logOutput, 'Queue::forceReconnect() - connected!' . PHP_EOL);
159
160
        return $this->channel;
161
    }
162
}
163