| Conditions | 3 |
| Paths | 3 |
| Total Lines | 26 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 22 | public function __construct($packageRoot, Request $request) |
||
| 23 | { |
||
| 24 | $this->response = null; |
||
| 25 | |||
| 26 | $packageRoot = rtrim($packageRoot, '/'); |
||
| 27 | $path = $packageRoot . '/Route/' . $request->route() . '/' . $request->method() . '.php'; |
||
| 28 | if (file_exists($path)) { |
||
| 29 | require $path; |
||
| 30 | $controllerClass = $request->package() . '\\Route_' . str_replace('/', '_', $request->route()) . '\\' . $request->method(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var BaseController $controller |
||
| 34 | */ |
||
| 35 | $controller = new $controllerClass($packageRoot, $request); |
||
|
|
|||
| 36 | |||
| 37 | /** |
||
| 38 | * Call handler. |
||
| 39 | */ |
||
| 40 | $handler = $_POST['handler'] ?? $_GET['handler'] ?? 'index'; |
||
| 41 | $handler = str_replace('.', '', $handler); |
||
| 42 | if (method_exists($controllerClass, $handler)) { |
||
| 43 | $controller->$handler(); |
||
| 44 | $this->response = $controller->getResponse(); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 60 | } |
$controllerClasscan contain request data and is used in code execution context(s) leading to a potential security vulnerability.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: