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/BoundSocket/TCP.php (7 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\BoundSocket;
3
4
use PHPDaemon\Core\Daemon;
5
6
/**
7
 * TCP
8
 *
9
 * @package Core
10
 *
11
 * @author  Vasily Zorin <[email protected]>
12
 */
13
class TCP extends Generic
14
{
15
    /**
16
     * Hostname
17
     * @var string
18
     */
19
    protected $host;
20
21
    /**
22
     * Port
23
     * @var integer
24
     */
25
    protected $port;
26
27
    /**
28
     * Default port
29
     * @var integer
30
     */
31
    protected $defaultPort;
32
33
    /**
34
     * Sets default port
35
     * @param integer Port
36
     * @return void
37
     */
38
    public function setDefaultPort($port)
39
    {
40
        $this->defaultPort = $port;
41
    }
42
43
    /**
44
     * Bind the socket
45
     * @return null|boolean Success.
46
     */
47
    public function bindSocket()
48
    {
49
        if ($this->erroneous) {
50
            return false;
51
        }
52
        $port = $this->getPort();
53 View Code Duplication
        if (!is_int($port)) {
0 ignored issues
show
This code seems to be duplicated across 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...
54
            Daemon::log(get_class($this) . ' (' . get_class($this->pool) . '): no port defined for \'' . $this->uri['uri'] . '\'');
55
            return;
56
        }
57
        if (($port < 1024) && Daemon::$config->user->value !== 'root') {
58
            $this->listenerMode = false;
59
        }
60
        if ($this->listenerMode) {
61
            $this->setFd($this->host . ':' . $port);
62
            return true;
63
        }
64
        $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
65 View Code Duplication
        if (!$sock) {
0 ignored issues
show
This code seems to be duplicated across 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...
66
            $errno = socket_last_error();
67
            Daemon::$process->log(get_class($this->pool) . ': Couldn\'t create TCP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
68
            return false;
69
        }
70 View Code Duplication
        if ($this->reuse) {
0 ignored issues
show
This code seems to be duplicated across 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...
71
            if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
72
                $errno = socket_last_error();
73
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t set option REUSEADDR to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
74
                return false;
75
            }
76
            if (defined('SO_REUSEPORT') && !@socket_set_option($sock, SOL_SOCKET, SO_REUSEPORT, 1)) {
77
                $errno = socket_last_error();
78
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t set option REUSEPORT to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
79
                return false;
80
            }
81
        }
82 View Code Duplication
        if (!@socket_bind($sock, $this->host, $port)) {
0 ignored issues
show
This code seems to be duplicated across 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...
83
            $errno = socket_last_error();
84
            Daemon::$process->log(get_class($this->pool) . ': Couldn\'t bind TCP-socket \'' . $this->host . ':' . $port . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').');
85
            return false;
86
        }
87
        socket_getsockname($sock, $this->host, $this->port);
88
        socket_set_nonblock($sock);
89 View Code Duplication
        if (!$this->listenerMode) {
0 ignored issues
show
This code seems to be duplicated across 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...
90
            if (!socket_listen($sock, SOMAXCONN)) {
91
                $errno = socket_last_error();
92
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t listen TCP-socket \'' . $this->host . ':' . $port . '\' (' . $errno . ' - ' . socket_strerror($errno) . ')');
93
                return false;
94
            }
95
        }
96
        $this->setFd($sock);
97
        return true;
98
    }
99
100
    /**
101
     * Called when socket is bound
102
     * @return boolean|null Success
103
     */
104
    protected function onBound()
105
    {
106
        if ($this->ev) {
107
            $this->ev->getSocketName($this->locHost, $this->locPort);
0 ignored issues
show
The property locHost does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
The property locPort does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
108
        } else {
109
            Daemon::log('Unable to bind TCP-socket ' . $this->host . ':' . $this->getPort());
110
        }
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getPort()
117
    {
118
        return isset($this->port) ? $this->port : $this->defaultPort;
119
    }
120
}
121