big update base struktur tahap 1

This commit is contained in:
Wian Drs
2026-07-27 16:24:09 +07:00
parent 2b3592c4c2
commit 1dd02baa72
169 changed files with 24405 additions and 977 deletions
+10 -2
View File
@@ -30,7 +30,7 @@ class Filesystem implements FilesystemOperator
private ?TemporaryUrlGenerator $temporaryUrlGenerator = null,
) {
$this->config = new Config($config);
$this->pathNormalizer = $pathNormalizer ?? new WhitespacePathNormalizer();
$this->pathNormalizer = $pathNormalizer ?? new WhitespacePathNormalizer($this->config->get('allow_relative_path_traversal', true));
}
public function fileExists(string $location): bool
@@ -168,9 +168,17 @@ class Filesystem implements FilesystemOperator
public function mimeType(string $path): string
{
return $this->adapter->mimeType($this->pathNormalizer->normalizePath($path))->mimeType();
$normalizedPath = $this->pathNormalizer->normalizePath($path);
$attributes = $this->adapter->mimeType($normalizedPath);
if ($attributes->mimeType() === null) {
throw UnableToRetrieveMetadata::mimeType($path);
}
return $attributes->mimeType();
}
public function setVisibility(string $path, string $visibility): void
{
$this->adapter->setVisibility($this->pathNormalizer->normalizePath($path), $visibility);
+18 -13
View File
@@ -4,37 +4,42 @@ declare(strict_types=1);
namespace League\Flysystem;
use function array_pop;
use function explode;
use function implode;
use function preg_match;
use function str_replace;
class WhitespacePathNormalizer implements PathNormalizer
{
private bool $allowRelativePaths;
public function __construct(bool $allowRelativePathTraversal = true)
{
$this->allowRelativePaths = $allowRelativePathTraversal;
}
public function normalizePath(string $path): string
{
$path = str_replace('\\', '/', $path);
$this->rejectFunkyWhiteSpace($path);
$unixPath = str_replace('\\', '/', $path);
return $this->normalizeRelativePath($path);
}
private function rejectFunkyWhiteSpace(string $path): void
{
if (preg_match('#\p{C}+#u', $path)) {
if (preg_match('#\p{C}+#u', $unixPath)) {
throw CorruptedPathDetected::forPath($path);
}
}
private function normalizeRelativePath(string $path): string
{
$parts = [];
foreach (explode('/', $path) as $part) {
foreach (explode('/', $unixPath) as $part) {
switch ($part) {
case '':
case '.':
break;
case '..':
if (empty($parts)) {
if ($this->allowRelativePaths === false || empty($parts)) {
throw PathTraversalDetected::forPath($path);
}
array_pop($parts);
break;