Issues (11)

Security Analysis    no request data  

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/TerminalObject/Router/Router.php (1 issue)

Labels
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
3
namespace League\CLImate\TerminalObject\Router;
4
5
use League\CLImate\Decorator\Parser\ParserImporter;
6
use League\CLImate\Settings\Manager;
7
use League\CLImate\Settings\SettingsImporter;
8
use League\CLImate\Util\OutputImporter;
9
use League\CLImate\Util\UtilImporter;
10
11
class Router
12
{
13
    use ParserImporter, SettingsImporter, OutputImporter, UtilImporter;
14
15
    /**
16
     * An instance of the Settings Manager class
17
     *
18
     * @var \League\CLImate\Settings\Manager $settings;
19
     */
20
    protected $settings;
21
22
    /**
23
     * An instance of the Dynamic Router class
24
     *
25
     * @var \League\CLImate\TerminalObject\Router\DynamicRouter $dynamic;
26
     */
27
    protected $dynamic;
28
29
    /**
30
     * An instance of the Basic Router class
31
     *
32
     * @var \League\CLImate\TerminalObject\Router\BasicRouter $basic;
33
     */
34
    protected $basic;
35
36 948
    public function __construct(DynamicRouter $dynamic = null, BasicRouter $basic = null)
37
    {
38 948
        $this->dynamic = $dynamic ?: new DynamicRouter();
39 948
        $this->basic   = $basic ?: new BasicRouter();
40 948
    }
41
42
    /**
43
     * Register a custom class with the router
44
     *
45
     * @param string $key
46
     * @param string $class
47
     */
48 36
    public function addExtension($key, $class)
49
    {
50 36
        $extension = new ExtensionCollection($key, $class);
51
52 28
        foreach ($extension->collection() as $obj_type => $collection) {
53 28
            foreach ($collection as $obj_key => $obj_class) {
54 28
                $this->{$obj_type}->addExtension($obj_key, $obj_class);
55 28
            }
56 28
        }
57 28
    }
58
59
    /**
60
     * Check if the name matches an existing terminal object
61
     *
62
     * @param string $name
63
     *
64
     * @return boolean
65
     */
66 580
    public function exists($name)
67
    {
68 580
        return ($this->basic->exists($name) || $this->dynamic->exists($name));
69
    }
70
71
    /**
72
     * Execute a terminal object using given arguments
73
     *
74
     * @param string $name
75
     * @param mixed  $arguments
76
     *
77
     * @return null|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface
78
     */
79 568
    public function execute($name, $arguments)
80
    {
81 568
        $router = $this->getRouter($name);
82
83 568
        $router->output($this->output);
84
85 568
        $obj = $this->getObject($router, $name, $arguments);
0 ignored issues
show
It seems like $router defined by $this->getRouter($name) on line 81 can also be of type null; however, League\CLImate\TerminalO...ter\Router::getObject() does only seem to accept object<League\CLImate\Te...Router\RouterInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
86
87 568
        $obj->parser($this->parser);
88 568
        $obj->util($this->util);
89
90
        // If the object needs any settings, import them
91 568
        foreach ($obj->settings() as $obj_setting) {
92 80
            $setting = $this->settings->get($obj_setting);
93
94 80
            if ($setting) {
95 44
                $obj->importSetting($setting);
96 44
            }
97 568
        }
98
99 568
        return $router->execute($obj);
100
    }
101
102
    /**
103
     * Get the object whether it's a string or already instantiated
104
     *
105
     * @param \League\CLImate\TerminalObject\Router\RouterInterface $router
106
     * @param string $name
107
     * @param array $arguments
108
     *
109
     * @return \League\CLImate\TerminalObject\Dynamic\DynamicTerminalObjectInterface|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface
110
     */
111 568
    protected function getObject($router, $name, $arguments)
112
    {
113 568
        $obj = $router->path($name);
114
115 568
        if (is_string($obj)) {
116 560
            $obj = (new \ReflectionClass($obj))->newInstanceArgs($arguments);
117 560
        }
118
119 568
        if (method_exists($obj, 'arguments')) {
120 4
            call_user_func_array([$obj, 'arguments'], $arguments);
121 4
        }
122
123 568
        return $obj;
124
    }
125
126
    /**
127
     * Determine which type of router we are using and return it
128
     *
129
     * @param string $name
130
     *
131
     * @return \League\CLImate\TerminalObject\Router\RouterInterface|null
132
     */
133 568
    protected function getRouter($name)
134
    {
135 568
        if ($this->basic->exists($name)) {
136 356
            return $this->basic;
137
        }
138
139 224
        if ($this->dynamic->exists($name)) {
140 224
            return $this->dynamic;
141
        }
142
    }
143
144
    /**
145
     * Set the settings property
146
     *
147
     * @param  \League\CLImate\Settings\Manager $settings
148
     *
149
     * @return Router
150
     */
151 568
    public function settings(Manager $settings)
152
    {
153 568
        $this->settings = $settings;
154
155 568
        return $this;
156
    }
157
}
158