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/Applications/CGIRequest.php (12 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\Applications;
3
4
use PHPDaemon\HTTPRequest\Generic;
5
6
/**
7
 * @property mixed stream
8
 * @package    Applications
9
 * @subpackage CGI
10
 *
11
 * @author     Vasily Zorin <[email protected]>
12
 */
13
class CGIRequest extends Generic
14
{
15
    /**
16
     * @var bool
17
     */
18
    public $terminateOnAbort = false;
19
    /**
20
     * @var \PHPDaemon\Core\ShellCommand
21
     */
22
    public $proc;
23
24
    /**
25
     * Constructor.
26
     * @return void
27
     */
28
    public function init()
29
    {
30
        $this->header('Content-Type: text/html'); // default header.
31
32
        $this->proc = new \PHPDaemon\Core\ShellCommand();
33
        $this->proc->readPacketSize = $this->appInstance->readPacketSize;
0 ignored issues
show
The property readPacketSize does not exist on object<PHPDaemon\Core\ShellCommand>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property readPacketSize does not exist on object<PHPDaemon\Core\AppInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
34
        $this->proc->onReadData([$this, 'onReadData']);
0 ignored issues
show
Documentation Bug introduced by
The method onReadData does not exist on object<PHPDaemon\Core\ShellCommand>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
35
        $this->proc->onWrite([$this, 'onWrite']);
0 ignored issues
show
The call to ShellCommand::onWrite() has too many arguments starting with array($this, 'onWrite').

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...
36
        $this->proc->binPath = $this->appInstance->binPath;
0 ignored issues
show
The property binPath does not exist on object<PHPDaemon\Core\AppInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37
        $this->proc->chroot = $this->appInstance->chroot;
0 ignored issues
show
The property chroot does not exist on object<PHPDaemon\Core\AppInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
39
        if (isset($this->attrs->server['BINPATH'])) {
40
            if (isset($this->appInstance->binAliases[$this->attrs->server['BINPATH']])) {
41
                $this->proc->binPath = $this->appInstance->binAliases[$this->attrs->server['BINPATH']];
0 ignored issues
show
The property binAliases does not seem to exist in PHPDaemon\Core\AppInstance.

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...
42
            } elseif ($this->appInstance->config->allowoverridebinpath->value) {
43
                $this->proc->binPath = $this->attrs->server['BINPATH'];
44
            }
45
        }
46
47 View Code Duplication
        if (isset($this->attrs->server['CHROOT']) && $this->appInstance->config->allowoverridechroot->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...
48
            $this->proc->chroot = $this->attrs->server['CHROOT'];
49
        }
50
51 View Code Duplication
        if (isset($this->attrs->server['SETUSER']) && $this->appInstance->config->allowoverrideuser->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...
52
            $this->proc->setUser = $this->attrs->server['SETUSER'];
53
        }
54
55 View Code Duplication
        if (isset($this->attrs->server['SETGROUP']) && $this->appInstance->config->allowoverridegroup->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...
56
            $this->proc->setGroup = $this->attrs->server['SETGROUP'];
57
        }
58
59
        if (isset($this->attrs->server['CWD']) && $this->appInstance->config->allowoverridecwd->value) {
60
            $this->proc->cwd = $this->attrs->server['CWD'];
61
        } elseif ($this->appInstance->config->cwd->value !== null) {
62
            $this->proc->cwd = $this->appInstance->config->cwd->value;
63
        } else {
64
            $this->proc->cwd = dirname($this->attrs->server['SCRIPT_FILENAME']);
65
        }
66
67
        $this->proc->setArgs([$this->attrs->server['SCRIPT_FILENAME']]);
68
        $this->proc->setEnv($this->attrs->server);
69
        $this->proc->execute();
70
    }
71
72
    /**
73
     * Called when request iterated.
74
     * @return void
75
     */
76
    public function run()
77
    {
78
        if (!$this->proc) {
79
            $this->out('Couldn\'t execute CGI proccess.');
80
            $this->finish();
81
            return;
82
        }
83
        if (!$this->proc->eof()) {
84
            $this->sleep();
85
        }
86
    }
87
88
    /**
89
     * Called when the request aborted.
90
     * @return void
91
     */
92
    public function onAbort()
93
    {
94
        if ($this->terminateOnAbort && $this->stream) {
95
            $this->stream->close();
96
        }
97
    }
98
99
    /**
100
     * Called when new data received from process.
101
     * @param object $process Process pointer.
102
     * @param string $data Data.
103
     * @return void
104
     */
105
    public function onReadData($process, $data)
106
    {
107
        $this->combinedOut($data);
108
    }
109
110
    /**
111
     * Called when new piece of request's body is received.
112
     * @param string $c Piece of request's body.
113
     * @return void
114
     */
115
    public function stdin($c)
116
    {
117
        if ($c === '') {
118
            $this->onWrite($this->proc);
119
        } else {
120
            $this->proc->write($c);
121
        }
122
    }
123
124
    /**
125
     * Called when the request aborted.
126
     * @param \PHPDaemon\Core\ShellCommand $process
127
     * @return void
128
     */
129
    public function onWrite($process)
0 ignored issues
show
The parameter $process 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...
130
    {
131
        if ($this->attrs->stdin_done && ($this->proc->writeState === false)) {
0 ignored issues
show
The property writeState does not exist on object<PHPDaemon\Core\ShellCommand>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
132
            $this->proc->closeWrite();
133
        }
134
    }
135
}
136