Issues (9)

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/Commands/RabbitmqCommands.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 Drupal\rabbitmq\Commands;
4
5
use Consolidation\OutputFormatters\StructuredData\PropertyList;
6
use Drupal\rabbitmq\ConnectionFactory;
7
use Drupal\rabbitmq\Consumer;
8
use Drupal\rabbitmq\Service\QueueInfo;
9
use Drush\Commands\DrushCommands;
10
use PhpAmqpLib\Connection\AMQPStreamConnection;
11
use PhpAmqpLib\Message\AMQPMessage;
12
13
/**
14
 * Implementation of the Drush commands for RabbitMQ.
15
 */
16
class RabbitmqCommands extends DrushCommands {
17
18
  const WORKER_DEFAULTS = [
19
    Consumer::OPTION_MEMORY_LIMIT => NULL,
20
    Consumer::OPTION_MAX_ITERATIONS => NULL,
21
    Consumer::OPTION_TIMEOUT => NULL,
22
  ];
23
24
  /**
25
   * The rabbitmq.queue_info service.
26
   *
27
   * @var \Drupal\rabbitmq\Service\QueueInfo
28
   */
29
  protected $queueInfo;
30
31
  /**
32
   * The rabbitmq.consumer service.
33
   *
34
   * @var \Drupal\rabbitmq\Consumer
35
   */
36
  protected $consumer;
37
38
  /**
39
   * RabbitmqCommands constructor.
40
   *
41
   * @param \Drupal\rabbitmq\Service\QueueInfo $queueInfo
42
   *   The rabbitmq.queue_info service.
43
   * @param \Drupal\rabbitmq\Consumer $consumer
44
   *   The rabbitmq.consumer service.
45
   */
46
  public function __construct(
47
    QueueInfo $queueInfo,
48
    Consumer $consumer
49
  ) {
50
    $this->queueInfo = $queueInfo;
51
    $this->consumer = $consumer;
52
  }
53
54
  /**
55
   * Connect to RabbitMQ and wait for jobs to do.
56
   *
57
   * @param string $queueName
58
   *   The name of the queue to process, also the name of the worker plugin.
59
   * @param mixed $options
60
   *   The command options.
61
   *
62
   * @return int
0 ignored issues
show
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
63
   *   Exit code.
64
   *
65
   * @command rabbitmq:worker
66
   * @option Consumer::OPTION_MEMORY_LIMIT
67
   *   Set the max amount of memory the worker should occupy before exiting.
68
   *   Given in megabytes.
69
   * @option Consumer::OPTION_MAX_ITERATIONS
70
   *   Number of iterations to process before exiting.If not present, exit
71
   *   criteria will not evaluate the amount of iterations processed.
72
   * @option Consumer::OPTION_TIMEOUT
73
   *   Timeout to limit time worker should keep waiting messages from RabbitMQ.
74
   * @aliases rqwk
75
   */
76
  public function worker($queueName, $options = self::WORKER_DEFAULTS) {
77
    $this->consumer->setOptionGetter(function (string $name) use ($options) {
78
      return (int) $options[$name];
79
    });
80
81
    drupal_register_shutdown_function(function () use ($queueName) {
82
      $this->consumer->shutdownQueue($queueName);
83
    });
84
85
    $this->consumer->logStart();
86
    $this->consumer->consumeQueueApi($queueName);
87
  }
88
89
  /**
90
   * Return information about a queue.
91
   *
92
   * @param string|null $queueName
93
   *   The name of the queue to get information from.
94
   *
95
   * @return \Consolidation\OutputFormatters\StructuredData\PropertyList|null
96
   *   The command result.
97
   *
98
   * @command rabbitmq:queue-info
99
   * @aliases rqqi
100
   * @field-labels
101
   *   queue-name: Queue name
102
   *   count: Items count
103
   */
104
  public function queueInfo($queueName = NULL) {
105
    if (NULL === $queueName) {
106
      $this->yell('Queue name required.', NULL, 'red');
107
      return NULL;
108
    }
109
    $count = $this->queueInfo->count($queueName);
110
111
    return new PropertyList(['queue-name' => $queueName, 'count' => $count]);
112
  }
113
114
  /**
115
   * Run the RabbitMQ tutorial test producer.
116
   *
117
   * @see https://www.rabbitmq.com/tutorials/tutorial-one-php.html
118
   *
119
   * @command rabbitmq:test-producer
120
   * @aliases rqtp
121
   */
122 View Code Duplication
  public function testProducer() {
123
    $connection = new AMQPStreamConnection(
124
      ConnectionFactory::DEFAULT_HOST,
125
      ConnectionFactory::DEFAULT_PORT,
126
      ConnectionFactory::DEFAULT_USER,
127
      ConnectionFactory::DEFAULT_PASS
128
    );
129
    $channel = $connection->channel();
130
    $routingKey = $queueName = 'hello';
131
    $channel->queue_declare($queueName, FALSE, FALSE, FALSE, FALSE);
132
    $message = new AMQPMessage('Hello World!');
133
    $channel->basic_publish($message, '', $routingKey);
134
    $this->writeln(" [x] Sent 'Hello World!'");
135
    $channel->close();
136
    $connection->close();
137
  }
138
139
  /**
140
   * Run the RabbitMQ tutorial test consumer.
141
   *
142
   * @see https://www.rabbitmq.com/tutorials/tutorial-one-php.html
143
   *
144
   * @command rabbitmq:test-consumer
145
   * @aliases rqtc
146
   */
147
  public function testConsumer() {
148
    $connection = new AMQPStreamConnection(
149
      ConnectionFactory::DEFAULT_HOST,
150
      ConnectionFactory::DEFAULT_PORT,
151
      ConnectionFactory::DEFAULT_USER,
152
      ConnectionFactory::DEFAULT_PASS
153
    );
154
    $channel = $connection->channel();
155
    $queueName = 'hello';
156
    $channel->queue_declare($queueName, FALSE, FALSE, FALSE, FALSE);
157
    $this->writeln(' [*] Waiting for messages. To exit press CTRL+C');
158
159
    $callback = function ($msg) {
160
      $this->writeln(" [x] Received {$msg->body}");
161
    };
162
163
    $channel->basic_consume($queueName, '', FALSE, TRUE, FALSE, FALSE, $callback);
164
165
    while (count($channel->callbacks)) {
166
      $channel->wait();
167
    }
168
    $channel->close();
169
    $connection->close();
170
  }
171
172
}
173