Issues (45)

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.

src/Xhgui/ServiceContainer.php (1 issue)

Severity

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
use Slim\Slim;
3
use Slim\Views\Twig;
4
use Slim\Middleware\SessionCookie;
5
6
class Xhgui_ServiceContainer extends Pimple
7
{
8
    protected static $_instance;
9
10
    public static function instance()
11
    {
12
        if (empty(static::$_instance)) {
13
            static::$_instance = new self();
14
        }
15
        return static::$_instance;
16
    }
17
18
    public function __construct()
19
    {
20
        $this->_slimApp();
21
        $this->_services();
22
        $this->_controllers();
0 ignored issues
show
The call to the method Xhgui_ServiceContainer::_controllers() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
23
    }
24
25
    // Create the Slim app.
26
    protected function _slimApp()
27
    {
28
        $this['view'] = function ($c) {
29
            $cacheDir = isset($c['config']['cache']) ? $c['config']['cache'] : XHGUI_ROOT_DIR . '/cache';
30
31
            // Configure Twig view for slim
32
            $view = new Twig();
33
34
            $view->twigTemplateDirs = array(dirname(__DIR__) . '/templates');
35
            $view->parserOptions = array(
36
                'charset' => 'utf-8',
37
                'cache' => $cacheDir,
38
                'auto_reload' => true,
39
                'strict_variables' => false,
40
                'autoescape' => true
41
            );
42
43
            return $view;
44
        };
45
46
        $this['app'] = $this->share(function ($c) {
47
            $app = new Slim($c['config']);
48
49
            // Enable cookie based sessions
50
            $app->add(new SessionCookie(array(
51
                'httponly' => true,
52
            )));
53
54
            // Add renderer.
55
            $app->add(new Xhgui_Middleware_Render());
56
57
            $view = $c['view'];
58
            $view->parserExtensions = array(
59
                new Xhgui_Twig_Extension($app)
60
            );
61
            $app->view($view);
62
63
            return $app;
64
        });
65
    }
66
67
    /**
68
     * Add common service objects to the container.
69
     */
70
    protected function _services()
71
    {
72
        $this['config'] = Xhgui_Config::all();
73
74
        $this['db'] = $this->share(function ($c) {
75
            $config = $c['config'];
76
            if (empty($config['db.options'])) {
77
                $config['db.options'] = array();
78
            }
79
            if (empty($config['db.driverOptions'])) {
80
                $config['db.driverOptions'] = array();
81
            }
82
            $mongo = new MongoClient($config['db.host'], $config['db.options'], $config['db.driverOptions']);
83
            $mongo->{$config['db.db']}->results->findOne();
84
85
            return $mongo->{$config['db.db']};
86
        });
87
88
        $this['pdo'] = $this->share(function ($c) {
89
            return new PDO(
90
                $c['config']['pdo']['dsn'],
91
                $c['config']['pdo']['pass'],
92
                $c['config']['pdo']['user']
93
            );
94
        });
95
96
        $this['searcher.mongo'] = function ($c) {
97
            return new Xhgui_Searcher_Mongo($c['db']);
98
        };
99
100
        $this['searcher.pdo'] = function ($c) {
101
            return new Xhgui_Searcher_Pdo($c['pdo'], $c['config']['pdo']['table']);
102
        };
103
104
        $this['searcher'] = function ($c) {
105
            $config = $c['config'];
106
107
            switch ($config['save.handler']) {
108
                case 'pdo':
109
                    return $c['searcher.pdo'];
110
111
                case 'mongodb':
112
                default:
113
                    return $c['searcher.mongo'];
114
            }
115
        };
116
117
        $this['saver.mongo'] = function ($c) {
118
            $config = $c['config'];
119
            $config['save.handler'] = 'mongodb';
120
121
            return Xhgui_Saver::factory($config);
122
        };
123
124
        $this['saver'] = function ($c) {
125
            return Xhgui_Saver::factory($c['config']);
126
        };
127
    }
128
129
    /**
130
     * Add controllers to the DI container.
131
     */
132
    protected function _controllers()
133
    {
134
        $this['watchController'] = function ($c) {
135
            return new Xhgui_Controller_Watch($c['app'], $c['searcher']);
136
        };
137
138
        $this['runController'] = function ($c) {
139
            return new Xhgui_Controller_Run($c['app'], $c['searcher']);
140
        };
141
142
        $this['customController'] = function ($c) {
143
            return new Xhgui_Controller_Custom($c['app'], $c['searcher']);
144
        };
145
146
        $this['waterfallController'] = function ($c) {
147
            return new Xhgui_Controller_Waterfall($c['app'], $c['searcher']);
148
        };
149
150
        $this['importController'] = function ($c) {
151
            return new Xhgui_Controller_Import($c['app'], $c['saver']);
152
        };
153
    }
154
155
}
156