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/UNIX.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
 * UNIX
8
 *
9
 * @package Core
10
 *
11
 * @author  Vasily Zorin <[email protected]>
12
 */
13
class UNIX extends Generic
14
{
15
    /**
16
     * @var \PHPDaemon\Config\Section
17
     */
18
    public $config;
19
    /**
20
     * Group
21
     * @var string
22
     */
23
    protected $group;
24
25
    /**
26
     * User
27
     * @var string
28
     */
29
    protected $user;
30
31
    /**
32
     * Path
33
     * @var string
34
     */
35
    protected $path;
36
    /**
37
     * Listener mode?
38
     * @var boolean
39
     */
40
    protected $listenerMode = false;
41
42
    /**
43
     * toString handler
44
     * @return string
45
     */
46
    public function __toString()
47
    {
48
        return $this->path;
49
    }
50
51
    /**
52
     * Bind socket
53
     * @return boolean Success.
54
     */
55
    public function bindSocket()
56
    {
57
        if ($this->erroneous) {
58
            return false;
59
        }
60
61
        if ($this->path === null && isset($this->uri['path'])) {
62
            $this->path = $this->uri['path'];
63
        }
64
65
        if (pathinfo($this->path, PATHINFO_EXTENSION) !== 'sock') {
66
            Daemon::$process->log('Unix-socket \'' . $this->path . '\' must has \'.sock\' extension.');
67
            return false;
68
        }
69
70
        if (file_exists($this->path)) {
71
            unlink($this->path);
72
        }
73
74
        if ($this->listenerMode) {
75
            $this->setFd('unix:' . $this->path);
76
            return true;
77
        }
78
        $sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
79 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...
80
            $errno = socket_last_error();
81
            Daemon::$process->log(get_class($this) . ': Couldn\'t create UNIX-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
82
            return false;
83
        }
84
85
        // SO_REUSEADDR is meaningless in AF_UNIX context
86
        if (!@socket_bind($sock, $this->path)) {
87
            if (isset($this->config->maxboundsockets->value)) { // no error-messages when maxboundsockets defined
0 ignored issues
show
The property maxboundsockets does not seem to exist in PHPDaemon\Config\Section.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
                return false;
89
            }
90
            $errno = socket_last_error();
91
            Daemon::$process->log(get_class($this) . ': Couldn\'t bind Unix-socket \'' . $this->path . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').');
92
            return false;
93
        }
94
        socket_set_nonblock($sock);
95
        $this->onBound();
96 View Code Duplication
        if (!socket_listen($sock, SOMAXCONN)) {
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...
97
            $errno = socket_last_error();
98
            Daemon::$process->log(get_class($this) . ': Couldn\'t listen UNIX-socket \'' . $this->path . '\' (' . $errno . ' - ' . socket_strerror($errno) . ')');
99
        }
100
        $this->setFd($sock);
101
        return true;
102
    }
103
104
    /**
105
     * Called when socket is bound
106
     * @return boolean Success
107
     */
108
    protected function onBound()
109
    {
110
        touch($this->path);
111
        chmod($this->path, 0770);
112
        if ($this->group === null && !empty($this->uri['pass'])) {
113
            $this->group = $this->uri['pass'];
114
        }
115 View Code Duplication
        if ($this->group === null && isset(Daemon::$config->group->value)) {
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...
116
            $this->group = Daemon::$config->group->value;
117
        }
118 View Code Duplication
        if ($this->group !== null) {
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...
119
            if (!@chgrp($this->path, $this->group)) {
120
                unlink($this->path);
121
                Daemon::log('Couldn\'t change group of the socket \'' . $this->path . '\' to \'' . $this->group . '\'.');
122
                return false;
123
            }
124
        }
125
        if ($this->user === null && !empty($this->uri['user'])) {
126
            $this->user = $this->uri['user'];
127
        }
128 View Code Duplication
        if ($this->user === null && isset(Daemon::$config->user->value)) {
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...
129
            $this->user = Daemon::$config->user->value;
130
        }
131 View Code Duplication
        if ($this->user !== null) {
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...
132
            if (!@chown($this->path, $this->user)) {
133
                unlink($this->path);
134
                Daemon::log('Couldn\'t change owner of the socket \'' . $this->path . '\' to \'' . $this->user . '\'.');
135
                return false;
136
            }
137
        }
138
        return true;
139
    }
140
}
141