Issues (6)

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/Producer/Producer.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 declare(strict_types=1);
2
3
namespace Mgid\KafkaBundle\Producer;
4
5
use JsonException;
6
use Mgid\KafkaBundle\Exception\UnableProduceException;
7
8
final class Producer
9
{
10
    public const DEFAULT_TIMEOUT = 1000;
11
    public const FLUSH_RETRY_COUNT = 10;
12
13
    private Configuration $configuration;
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...
14
15
    /**
16
     * @var \RdKafka\ProducerTopic[]
17
     */
18
    private array $topics = [];
19
20
    /**
21
     * @param Configuration $configuration
22
     */
23
    public function __construct(Configuration $configuration)
24
    {
25
        $this->configuration = $configuration;
26
    }
27
28
    /**
29
     * @param string       $name
30
     * @param array<mixed> $data
31
     * @param int          $timeout
32
     *
33
     * @throws JsonException
34
     * @throws UnableProduceException
35
     */
36
    public function send(string $name, array $data, int $timeout = self::DEFAULT_TIMEOUT): void
37
    {
38
        $payload = \json_encode($data, \JSON_THROW_ON_ERROR);
39
40
        $this->getTopic($name)->produce(\RD_KAFKA_PARTITION_UA, 0, $payload);
41
42
        for ($i = 0; $i < self::FLUSH_RETRY_COUNT; ++$i) {
43
            if (\RD_KAFKA_RESP_ERR_NO_ERROR === $this->getClient()->flush($timeout)) {
44
                return;
45
            }
46
        }
47
48
        throw new UnableProduceException($payload);
49
    }
50
51
    /**
52
     * @return \RdKafka\Producer
53
     */
54
    private function getClient(): \RdKafka\Producer
55
    {
56
        static $client = null;
57
58
        if (null === $client) {
59
            $client = new \RdKafka\Producer($this->configuration);
60
        }
61
62
        return $client;
63
    }
64
65
    /**
66
     * @param string $name
67
     *
68
     * @return \RdKafka\ProducerTopic
69
     */
70
    private function getTopic(string $name): \RdKafka\ProducerTopic
71
    {
72
        if (false === isset($this->topics[$name])) {
73
            $this->topics[$name] = $this->getClient()->newTopic($name);
74
        }
75
76
        return $this->topics[$name];
77
    }
78
}
79