fix(s3): ignore prefixes with repeating delimiters

Signed-off-by: Kent Delante <kent@delante.me>

Amazon's hosted S3 service allows repeating delimiters in keys
(e.g. 'path/to//file.txt' or 'path/to///file.txt') and we get
repeating directories in the filecache as a result (based on the
previous examples we get 'path/to/to/file.txt' or
'path/to/to/to/file.txt'). This ignores it and its contents for S3 external storage.
This commit is contained in:
Kent Delante 2026-04-13 12:05:15 +08:00 committed by backportbot[bot]
parent e511ce5041
commit 8d4fa6fa47

View file

@ -645,6 +645,12 @@ class AmazonS3 extends Common {
// sub folders
if (is_array($result['CommonPrefixes'])) {
foreach ($result['CommonPrefixes'] as $prefix) {
if (preg_match('/\/{2,}$/', $prefix['Prefix'])) {
$this->logger->warning('Detected a repeating delimiter in prefix \'' . $prefix['Prefix']
. '\'. This is unsupported and its contents have been ignored.');
continue;
}
$dir = $this->getDirectoryMetaData($prefix['Prefix']);
if ($dir) {
yield $dir;