Issues (1507)

Security Analysis    not enabled

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.

PHPDaemon/IPCManager/IPCManager.php (11 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
namespace PHPDaemon\IPCManager;
3
4
use PHPDaemon\Config;
5
use PHPDaemon\Core\AppInstance;
6
use PHPDaemon\Core\Daemon;
7
use PHPDaemon\Thread;
8
9
class IPCManager extends AppInstance
10
{
11
    /** @var */
12
    public $pool;
13
    /** @var */
14
    public $conn;
15
    /** @var */
16
    public $socketurl;
17
18
    /**
19
     * Setting default config options
20
     * Overriden from AppInstance::getConfigDefaults
21
     * @return array|bool
22
     */
23
    protected function getConfigDefaults()
24
    {
25
        return [
26
            // listen to
27
            'mastersocket' => 'unix:///tmp/phpDaemon-ipc-%x.sock',
28
        ];
29
    }
30
31
    /**
32
     * Constructor.
33
     * @return void
34
     */
35
    public function init()
36
    {
37
        $this->socketurl = sprintf($this->config->mastersocket->value,
38
            crc32(Daemon::$config->pidfile->value . "\x00" . Daemon::$config->user->value . "\x00" . Daemon::$config->group->value));
39
        if (Daemon::$process instanceof Thread\IPC) {
40
            $this->pool = MasterPool::getInstance(['listen' => $this->socketurl]);
0 ignored issues
show
array('listen' => $this->socketurl) is of type array<string,string,{"listen":"string"}>, 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...
41
            $this->pool->appInstance = $this;
42
            $this->pool->onReady();
43
        }
44
    }
45
46
    public function getSocketUrl()
47
    {
48
        return $this->socketurl;
49
    }
50
51
    /**
52
     * @TODO DESCR
53
     */
54
    public function updatedWorkers()
55
    {
56
        $perWorker = 1;
57
        $instancesCount = [];
58
        foreach (Daemon::$config as $name => $section) {
0 ignored issues
show
The expression \PHPDaemon\Core\Daemon::$config of type object<PHPDaemon\Config\_Object> is not traversable.
Loading history...
59
            if ((!$section instanceof Config\Section) || !isset($section->limitinstances)) {
60
                continue;
61
            }
62
            $instancesCount[$name] = 0;
63
        }
64
        foreach ($this->pool->workers as $worker) {
65
            foreach ($worker->instancesCount as $k => $v) {
66
                if (!isset($instancesCount[$k])) {
67
                    unset($worker->instancesCount[$k]);
68
                    continue;
69
                }
70
                $instancesCount[$k] += $v;
71
            }
72
        }
73
        foreach ($instancesCount as $name => $num) {
74
            $v = Daemon::$config->{$name}->limitinstances->value - $num;
75
            foreach ($this->pool->workers as $worker) {
76
                if ($v <= 0) {
77
                    break;
78
                }
79
                if ((isset($worker->instancesCount[$name])) && ($worker->instancesCount[$name] < $perWorker)) {
80
                    continue;
81
                }
82
                if (!isset($worker->instancesCount[$name])) {
83
                    $worker->instancesCount[$name] = 1;
84
                } else {
85
                    ++$worker->instancesCount[$name];
86
                }
87
                $worker->sendPacket(['op' => 'spawnInstance', 'appfullname' => $name]);
88
                --$v;
89
            }
90
        }
91
    }
92
93
    /**
94
     * Called when application instance is going to shutdown.
95
     * @param bool $graceful
96
     * @return boolean Ready to shutdown?
97
     */
98
    public function onShutdown($graceful = false)
99
    {
100
        if ($this->pool) {
101
            return $this->pool->onShutdown();
102
        }
103
        return true;
104
    }
105
106
    /**
107
     * @TODO DESCR
108
     * @param $workerId
109
     * @param $path
110
     * @return bool
111
     */
112
    public function importFile($workerId, $path)
113
    {
114
        if (!isset($this->pool->workers[$workerId])) {
115
            return false;
116
        }
117
        $worker = $this->pool->workers[$workerId];
118
        $worker->sendPacket(['op' => 'importFile', 'path' => $path]);
119
        return true;
120
    }
121
122
    /**
123
     * @TODO DESCR
124
     */
125
    public function ensureConnection()
126
    {
127
        $this->sendPacket('');
128
    }
129
130
    /**
131
     * @TODO DESCR
132
     * @param $packet
133
     */
134
    public function sendPacket($packet = null)
135
    {
136
        if ($this->conn && $this->conn->isConnected()) {
137
            $this->conn->sendPacket($packet);
138
            return;
139
        }
140
141
        $cb = function ($conn) use ($packet) {
142
            $conn->sendPacket($packet);
143
        };
144
        if (!$this->conn) {
145
            $this->conn = new WorkerConnection(null, null, null);
0 ignored issues
show
The call to WorkerConnection::__construct() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
146
            $this->conn->connect($this->socketurl);
147
        }
148
        $this->conn->onConnected($cb);
149
    }
150
151
    /**
152
     * @TODO DESCR
153
     * @param $appInstance
154
     * @param $method
155
     * @param array $args
156
     * @param callable $cb
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
157
     */
158 View Code Duplication
    public function sendBroadcastCall($appInstance, $method, $args = [], $cb = null)
0 ignored issues
show
The parameter $cb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
159
    {
160
        $this->sendPacket([
161
            'op' => 'broadcastCall',
162
            'appfullname' => $appInstance,
163
            'method' => $method,
164
            'args' => $args,
165
        ]);
166
    }
167
168
    /**
169
     * @TODO DESCR
170
     * @param $appInstance
171
     * @param $method
172
     * @param array $args
173
     * @param callable $cb
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
174
     */
175 View Code Duplication
    public function sendSingleCall($appInstance, $method, $args = [], $cb = null)
0 ignored issues
show
The parameter $cb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        $this->sendPacket([
178
            'op' => 'singleCall',
179
            'appfullname' => $appInstance,
180
            'method' => $method,
181
            'args' => $args,
182
        ]);
183
    }
184
185
    /**
186
     * @TODO DESCR
187
     * @param $workerId
188
     * @param $appInstance
189
     * @param $method
190
     * @param array $args
191
     * @param callable $cb
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
192
     */
193
    public function sendDirectCall($workerId, $appInstance, $method, $args = [], $cb = null)
0 ignored issues
show
The parameter $cb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
194
    {
195
        $this->sendPacket([
196
            'op' => 'directCall',
197
            'appfullname' => $appInstance,
198
            'method' => $method,
199
            'args' => $args,
200
            'workerId' => $workerId,
201
        ]);
202
    }
203
}
204