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/Examples/ExampleWithMongo.php (6 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\Examples;
3
4
/**
5
 * @package    Examples
6
 * @subpackage Mongo
7
 *
8
 * @author     Vasily Zorin <[email protected]>
9
 */
10
class ExampleWithMongo extends \PHPDaemon\Core\AppInstance
11
{
12
    public $mongo;
13
14
    /**
15
     * Constructor.
16
     * @return void
17
     */
18
    public function init()
19
    {
20
        $this->mongo = \PHPDaemon\Clients\Mongo\Pool::getInstance(['maxconnperserv' => 100]);
0 ignored issues
show
array('maxconnperserv' => 100) is of type array<string,integer,{"m...onnperserv":"integer"}>, 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...
21
    }
22
23
    /**
24
     * Creates Request.
25
     * @param object Request.
26
     * @param object Upstream application instance.
27
     * @return ExampleWithMongoRequest Request.
28
     */
29
    public function beginRequest($req, $upstream)
30
    {
31
        return new ExampleWithMongoRequest($this, $upstream, $req);
32
    }
33
}
34
35
class ExampleWithMongoRequest extends \PHPDaemon\HTTPRequest\Generic
36
{
37
38
    public $job;
39
40
    /**
41
     * Constructor.
42
     * @return void
43
     */
44
    public function init()
45
    {
46
        $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done
47
            $job->keep(); // prevent cleaning up results
48
            $this->wakeup(); // wake up the request immediately
49
50
        });
51
52
        $collection = $this->appInstance->mongo->{'testdb.testcollection'};
0 ignored issues
show
The property mongo 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...
53
        $collection->insert(['a' => microtime(true)]); // just pushing something
54
55
        $job('testquery', function ($name, $job) use ($collection) { // registering job named 'testquery'
56
57
            $collection->findOne(function ($result) use ($name, $job) { // calling Mongo findOne
58
59
                $job->setResult($name, $result);
60
61
            }, ['sort' => ['$natural' => -1]]);
62
        });
63
64
        $job(); // let the fun begin
65
66
        $this->sleep(1, true); // setting timeout
67
    }
68
69
    /**
70
     * Called when request iterated.
71
     * @return integer Status.
0 ignored issues
show
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
72
     */
73 View Code Duplication
    public function run()
0 ignored issues
show
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...
74
    {
75
        try {
76
            $this->header('Content-Type: text/html');
77
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
78
        }
79
        ?>
80
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
81
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
82
        <html xmlns="http://www.w3.org/1999/xhtml">
83
        <head>
84
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
85
            <title>Example with Mongo</title>
86
        </head>
87
        <body>
88
        <?php
89
        if ($r = $this->job->getResult('testquery')) {
90
            echo '<h1>It works! Be happy! ;-)</h1>Result of query: <pre>';
91
            var_dump($r);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($r); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
92
            echo '</pre>';
93
        } else {
94
            echo '<h1>Something went wrong! We have no result.</h1>';
95
        }
96
        echo '<br />Request (http) took: ' . round(microtime(true) - $this->attrs->server['REQUEST_TIME_FLOAT'], 6);
97
        ?>
98
        </body>
99
        </html>
100
        <?php
101
102
    }
103
}
104