mirror of
https://github.com/filegator/filegator.git
synced 2025-08-12 03:44:21 +02:00
path traversal fix
This commit is contained in:
@@ -241,6 +241,7 @@ class Filesystem implements Service
|
||||
) {
|
||||
$path = $this->separator;
|
||||
}
|
||||
|
||||
return $this->joinPaths($this->getPathPrefix(), $path);
|
||||
}
|
||||
|
||||
@@ -266,6 +267,9 @@ class Filesystem implements Service
|
||||
|
||||
private function joinPaths(string $path1, string $path2): string
|
||||
{
|
||||
$path1 = $this->escapeDots($path1);
|
||||
$path2 = $this->escapeDots($path2);
|
||||
|
||||
if (! $path2 || ! trim($path2, $this->separator)) {
|
||||
return $this->addSeparators($path1);
|
||||
}
|
||||
@@ -295,4 +299,14 @@ class Filesystem implements Service
|
||||
|
||||
return (string) array_pop($tmp);
|
||||
}
|
||||
|
||||
private function escapeDots(string $path): string
|
||||
{
|
||||
$path = preg_replace('/\\\+\.{2,}/', '', $path);
|
||||
$path = preg_replace('/\.{2,}\\\+/', '', $path);
|
||||
$path = preg_replace('/\/+\.{2,}/', '', $path);
|
||||
$path = preg_replace('/\.{2,}\/+/', '', $path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user