Commit df2e299d authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

UploadedFile: vérifie dans setPath que $path ne pointe pas en dehors du répertoire.

Showing with 30 additions and 1 deletion
+30 -1
......@@ -151,7 +151,10 @@ class UploadedFile
*/
public function setPath($path)
{
$this->path = $path;
if(!static::isSafePath($path)) {
throw new InvalidArgumentException("Unsafe path: $path");
}
$this->path = trim($path, '/');
return $this;
}
......@@ -495,4 +498,30 @@ class UploadedFile
{
return fwrite($filehandle, $maxlen);
}
/** Vérifie si
*
* @param string $path
* @return boolean
*/
public static function isSafePath($path)
{
$parts = explode('/', trim($path, '/'));
$level = 0;
foreach($parts as $part) {
switch($part) {
case '.':
break;
case '..':
$level--;
if($level < 0) {
return false;
}
break;
default:
$level++;
}
}
return true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment