Issues (243)

Security Analysis    2 potential vulnerabilities

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 (2)
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/cli/Console.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 /** MicroConsole */
2
3
namespace Micro\Cli;
4
5
use Micro\Base\Exception;
6
use Micro\Web\ResponseInjector;
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * Console class file.
11
 *
12
 * @author Oleg Lunegov <[email protected]>
13
 * @link https://github.com/linpax/microphp-framework
14
 * @copyright Copyright (c) 2013 Oleg Lunegov
15
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
16
 * @package Micro
17
 * @subpackage Cli
18
 * @version 1.0
19
 * @since 1.0
20
 * @abstract
21
 */
22
class Console
23
{
24
    /** @var string $command Parsed command */
25
    protected $command;
26
27
28
    /**
29
     * Constructor command
30
     *
31
     * @access public
32
     * @result void
33
     */
34
    public function __construct()
35
    {
36
    }
37
38
    /**
39
     * Run action of console command by name
40
     *
41
     * @access public
42
     *
43
     * @param string $name Command name
44
     *
45
     * @return ResponseInterface
46
     * @throws \RuntimeException|\InvalidArgumentException|Exception
47
     */
48
    public function action($name)
49
    {
50
        $command = '\\App\\Consoles\\'.ucfirst($name).'ConsoleCommand';
51
        $command = class_exists($command) ? $command : '\\Micro\\Cli\\Consoles\\'.ucfirst($name).'ConsoleCommand';
52
53
        if (!class_exists($command)) {
54
            throw new Exception('Command `'.$name.'` not found');
55
        }
56
57
        /** @var ConsoleCommand $command */
58
        $command = new $command();
0 ignored issues
show
Security Code Execution introduced by
$command can contain request data and is used in code execution context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_GET, and $query ?: $_GET is passed to ServerRequest::__construct()
    in vendor/src/ServerRequestFactory.php on line 71
  2. ServerRequest::$queryParams is assigned
    in vendor/src/ServerRequest.php on line 101
  3. Tainted property ServerRequest::$queryParams is read
    in vendor/src/ServerRequest.php on line 156
  4. ServerRequest::getQueryParams() returns tainted data, and $rawQuery is assigned
    in src/mvc/MvcResolver.php on line 53
  5. $query is assigned
    in src/mvc/MvcResolver.php on line 55
  6. $query is assigned
    in src/mvc/MvcResolver.php on line 56
  7. MvcResolver::$uri is assigned
    in src/mvc/MvcResolver.php on line 58
  8. Tainted property MvcResolver::$uri is read, and $this->uri is passed through substr(), and substr($this->uri, 0, $key ?: strlen($this->uri)) is passed through explode(), and $uriBlocks is assigned
    in src/mvc/MvcResolver.php on line 84
  9. $uriBlocks is passed to MvcResolver::prepareAction()
    in src/mvc/MvcResolver.php on line 93
  10. $uriBlocks is passed through array_shift(), and MvcResolver::$action is assigned
    in src/mvc/MvcResolver.php on line 202
  11. Tainted property MvcResolver::$action is read
    in src/mvc/MvcResolver.php on line 264
  12. MvcResolver::getAction() returns tainted data, and $action is assigned
    in src/base/Application.php on line 88
  13. (string) $action is passed to Console::action()
    in src/base/Application.php on line 97
  14. $name is passed through ucfirst(), and $command is assigned
    in src/cli/Console.php on line 51

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
59
        $command->execute();
60
61
        $response = (new ResponseInjector)->build();
62
        $response = $response->withHeader('status', (string)(int)$command->result);
63
64
        $stream = $response->getBody();
65
        $stream->write($command->message);
66
67
        return $response->withBody($stream);
68
    }
69
}
70