Issues (5)

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.

src/Consumer/Consumer.php (2 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
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Krishnaprasad MG <[email protected]>
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Sunspikes\Carrot\Consumer;
27
28
use PhpAmqpLib\Message\AMQPMessage;
29
use Sunspikes\Carrot\AMQPConnectionTrait;
30
use Sunspikes\Carrot\ConfigAwareTrait;
31
use Sunspikes\Carrot\Exception\ConsumerException;
32
use PhpAmqpLib\Channel\AMQPChannel;
33
34
/**
35
 * Queue consumer
36
 */
37
class Consumer implements ConsumerInterface, AMQPConsumerInterface
38
{
39
    use AMQPConnectionTrait,
40
        ConfigAwareTrait;
41
42
    protected $channel;
43
    protected $exchange;
44
45
    /**
46
     * @param AMQPChannel $channel
47
     * @param string $exchange
48
     */
49
    public function __construct(AMQPChannel $channel, $exchange)
50
    {
51
        $this->channel = $channel;
52
        $this->exchange = $exchange;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function add($name, callable $callable)
59
    {
60
        try {
61
            $config = $this->config;
62
            $this->channel->queue_declare(
63
                $name,
64
                $config['queue']['passive'],
65
                $config['queue']['durable'],
66
                $config['queue']['exclusive'],
67
                $config['queue']['auto_delete'],
68
                $config['queue']['no_wait'],
69
                $config['queue']['arguments'],
70
                $config['queue']['ticket']
71
            );
72
            $this->channel->queue_bind(
73
                $name,
74
                $this->exchange,
75
                $name,
76
                $config['queue']['no_wait'],
77
                $config['queue']['arguments'],
78
                $config['queue']['ticket']
79
            );
80
            $this->channel->basic_consume(
81
                $name,
82
                $config['consumer']['consumer_tag'],
83
                $config['consumer']['no_local'],
84
                $config['consumer']['no_ack'],
85
                $config['consumer']['exclusive'],
86
                $config['consumer']['no_wait'],
87
                function (AMQPMessage $message) use ($callable, $config) {
88
                    $originalMessage = $message;
89
90
                    if (true === $config['delegate']) {
91
                        $message = $this->decodeMessage($originalMessage);
92
                    }
93
94
                    call_user_func($callable, $message);
95
96
                    if (true === $config['delegate']) {
97
                        $this->acknowledgeMessage($originalMessage);
98
                    }
99
                },
100
                $config['consumer']['ticket'],
101
                $config['consumer']['arguments']
102
            );
103
        } catch (\Exception $e) {
104
            throw new ConsumerException('Carrot consumer failed to add service: '. $e->getMessage());
105
        }
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111
    public function decodeMessage(AMQPMessage $message)
112
    {
113
        return json_decode($message->body);
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119
    public function acknowledgeMessage(AMQPMessage $message)
120
    {
121
        $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
0 ignored issues
show
$message->delivery_info['delivery_tag'] is of type object<PhpAmqpLib\Channel\AMQPChannel>, but the function expects a string.

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...
122
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127
    public function rejectMessage(AMQPMessage $message, $requeue = false)
128
    {
129
        $message->delivery_info['channel']->basic_reject($message->delivery_info['delivery_tag'], $requeue);
0 ignored issues
show
$message->delivery_info['delivery_tag'] is of type object<PhpAmqpLib\Channel\AMQPChannel>, but the function expects a string.

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...
130
    }
131
132
    /**
133
     * @inheritdoc
134
     */
135
    public function listen()
136
    {
137
        try {
138
            while(count($this->channel->callbacks)) {
139
                if (! $this->channel->getConnection()->isConnected()) {
140
                    throw new ConsumerException('Carrot consumer disconnected');
141
                }
142
                $this->channel->wait(null, true);
143
            }
144
145
            $this->closeConnection();
146
        } catch (\Exception $e) {
147
            // consumer failed to listen or disconnected
148
            throw new ConsumerException("Carrot lost connection with RabbitMQ server");
149
        }
150
    }
151
}
152
153