| Conditions | 8 |
| Paths | 13 |
| Total Lines | 21 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | private static function removeFromDir($dir, $self = false) |
||
| 21 | { |
||
| 22 | if (is_dir($dir)) { |
||
| 23 | $objects = scandir($dir); |
||
|
|
|||
| 24 | foreach ($objects as $object) { |
||
| 25 | if ('.' != $object && '..' != $object) { |
||
| 26 | if ('dir' == filetype($dir . '/' .$object)) { |
||
| 27 | self::removeFromDir($dir . '/' . $object, true); |
||
| 28 | } else { |
||
| 29 | unlink($dir . '/' . $object); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | } |
||
| 33 | if ($self) { |
||
| 34 | reset($objects); |
||
| 35 | if (count(scandir($dir)) == 2) { |
||
| 36 | rmdir($dir); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
$dircan contain request data and is used in file inclusion 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: