Fix same-window folder drop guard

This commit is contained in:
Mikei386
2026-06-23 12:05:14 +02:00
parent 25fa0ce644
commit 50c685ee80
7 changed files with 34 additions and 8 deletions
@@ -164,7 +164,9 @@ function unav_guard_destination(string $source, string $destination): void {
if (file_exists($destination)) {
unav_error(409, 'Destination already exists');
}
if ($source === $destination || str_starts_with($destination, rtrim($source, '/') . '/')) {
$normalizedSource = rtrim($source, '/');
$normalizedDestination = rtrim($destination, '/');
if ($normalizedSource === $normalizedDestination || (is_dir($source) && str_starts_with($normalizedDestination, $normalizedSource . '/'))) {
unav_error(400, 'Destination cannot be inside source');
}
}
@@ -54,7 +54,9 @@ function unav_worker_guard(string $source, string $destination): void {
if (file_exists($destinationPath)) {
throw new RuntimeException('Destination already exists');
}
if ($sourceReal === $destinationPath || str_starts_with($destinationPath, rtrim($sourceReal, '/') . '/')) {
$normalizedSource = rtrim($sourceReal, '/');
$normalizedDestination = rtrim($destinationPath, '/');
if ($normalizedSource === $normalizedDestination || (is_dir($sourceReal) && str_starts_with($normalizedDestination, $normalizedSource . '/'))) {
throw new RuntimeException('Destination cannot be inside source');
}
}