fix: Wurzelordner schützen und SVG-Vorschau absichern

- move, delete und permissions lehnen einen konfigurierten Root (z. B. /mnt/user)
  in job.php und erneut im Worker ab.
- preview.php?raw=1 sendet für SVG eine Sandbox-CSP, damit eingebettete Skripte
  nicht im WebGUI-Origin laufen.
- Job-Verzeichnis wird mit 0700 angelegt bzw. korrigiert.
- Paket 2026.11.21.r001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikei386andClaude Opus 5.5 committed 2026-11-21 12:43:13 +01:00
1 parent 4afacca2fb
commit 017ed6489a
7 files changed
+39 -4

No files matched your search

@@ -98,6 +98,22 @@ function unav_is_inside(string $path, string $root): bool {
return str_starts_with($path, rtrim($root, '/') . '/');
}
function unav_is_root(string $real): bool {
foreach (unav_roots() as $root) {
if (rtrim($real, '/') === rtrim($root['path'], '/')) {
return true;
}
}
return false;
}
// Destructive operations must never act on a configured root itself (e.g. /mnt/user).
function unav_assert_not_root(string $real): void {
if (unav_is_root($real)) {
unav_error(403, 'Root folders cannot be moved, deleted or changed');
}
}
function unav_root_for_real(string $real): array {
foreach (unav_roots() as $root) {
if (unav_is_inside($real, $root['path'])) {
@@ -239,9 +255,11 @@ function unav_permission_options(array $data): array {
}
function unav_job_dir(): string {
if (!is_dir(UNAV_JOB_DIR) && !mkdir(UNAV_JOB_DIR, 0777, true) && !is_dir(UNAV_JOB_DIR)) {
if (!is_dir(UNAV_JOB_DIR) && !mkdir(UNAV_JOB_DIR, 0700, true) && !is_dir(UNAV_JOB_DIR)) {
unav_error(500, 'Could not create job directory');
}
// Job files drive a root worker: keep them private, also for directories created by older versions.
@chmod(UNAV_JOB_DIR, 0700);
return UNAV_JOB_DIR;
}
@@ -14,6 +14,9 @@ $data = unav_request_data();
$source = unav_existing_path($data['source'] ?? null);
$destination = null;
$permissions = null;
if (in_array($action, ['move', 'delete', 'permissions'], true)) {
unav_assert_not_root($source['path']);
}
if (in_array($action, ['move', 'copy'], true)) {
unav_assert_writable();
$destination = unav_destination_path($data['destination'] ?? null);
@@ -10,6 +10,9 @@ function unav_run_job(string $id): void {
try {
unav_worker_update($job, 'running', 5, 'Preparing');
if (in_array($job['type'], ['move', 'delete', 'permissions'], true)) {
unav_worker_assert_not_root($job['source']);
}
if ($job['type'] === 'move') {
unav_worker_guard($job['source'], $job['destination']);
unav_worker_move($job['source'], $job['destination'], $job);
@@ -74,6 +77,13 @@ function unav_worker_guard_source(string $source): string {
return $sourceReal;
}
function unav_worker_assert_not_root(string $path): void {
$real = realpath($path);
if ($real !== false && unav_is_root($real)) {
throw new RuntimeException('Root folders cannot be moved, deleted or changed');
}
}
function unav_worker_assert_inside_root(string $path): void {
foreach (unav_roots() as $root) {
if (unav_is_inside($path, $root['path'])) {
@@ -87,6 +87,10 @@ if (($_GET['raw'] ?? '') === '1') {
header('Content-Type: ' . $mime);
header('Content-Length: ' . $size);
header('X-Content-Type-Options: nosniff');
if ($extension === 'svg') {
// Raw files are served from the WebGUI origin; scripts inside an SVG must not run there.
header("Content-Security-Policy: sandbox; default-src 'none'; img-src data:; style-src 'unsafe-inline'");
}
readfile($resolved['path']);
exit;
}