| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php /** MicroConsole */ |
||
| 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(); |
||
|
|
|||
| 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 |
$commandcan 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
$_GET,and$query ?: $_GETis passed to ServerRequest::__construct()in vendor/src/ServerRequestFactory.php on line 71
in vendor/src/ServerRequest.php on line 101
in vendor/src/ServerRequest.php on line 156
$rawQueryis assignedin src/mvc/MvcResolver.php on line 53
$queryis assignedin src/mvc/MvcResolver.php on line 55
$queryis assignedin src/mvc/MvcResolver.php on line 56
in src/mvc/MvcResolver.php on line 58
$this->uriis passed through substr(), andsubstr($this->uri, 0, $key ?: strlen($this->uri))is passed through explode(), and$uriBlocksis assignedin src/mvc/MvcResolver.php on line 84
$uriBlocksis passed to MvcResolver::prepareAction()in src/mvc/MvcResolver.php on line 93
$uriBlocksis passed through array_shift(), and MvcResolver::$action is assignedin src/mvc/MvcResolver.php on line 202
in src/mvc/MvcResolver.php on line 264
$actionis assignedin src/base/Application.php on line 88
(string) $actionis passed to Console::action()in src/base/Application.php on line 97
$nameis passed through ucfirst(), and$commandis assignedin 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: