Require auth for direct /files/ downloads

This commit is contained in:
Jeppe B
2026-06-01 23:09:37 +02:00
parent d82c7d88ec
commit 85f7bd1fc9
+16 -1
View File
@@ -5,6 +5,21 @@ $isPreview = $_GET['preview'] ?? false;
// Remove query string if present
$file = strtok($file, '?');
// Require authentication for direct /files/ access
if (str_contains($file, '/files/')) {
$headers = getallheaders();
$token = $_GET['token'] ?? $_POST['token'] ?? ($headers['Authorization'] ?? null);
if (!empty($token)) {
$token = str_replace('Bearer ', '', $token);
}
if (empty($token) || !(new \classes\authentication())->validate_token($token)) {
header('HTTP/1.1 401 Unauthorized');
echo 'Unauthorized';
exit;
}
}
$isPDF = false;
$isPDFStore = false;
$isAttachment = false;
@@ -118,4 +133,4 @@ if (!$isPDF) {
// Delete the file from /tmp after sending it
unlink($file_path);
exit;
}
}