Files
zoneminder/web/includes/actions/files.php
Isaac Connor 38a817353b fix: enforce Storage containment before deleting files
The delete action computed $is_ok_path to confirm the requested path sits
below a configured Storage area, but never consulted it, so the check was
dead code and unlink() ran on whatever path was supplied. The path comes
from detaintPathAllowAbsolute($_REQUEST['path']), which deliberately
permits absolute paths, so nothing else constrained the target.

Return with an error when the path is not below a Storage area. Deleting
already requires System Edit, so this is not reachable by a low privilege
user, but the containment check should do what it was written to do.

The adjacent $path_parts assignment is also unused; left in place as it
predates this change.

Refs GHSA-g355-3rf6-f38v.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 13:14:12 -04:00

68 lines
2.3 KiB
PHP

<?php
//
// ZoneMinder web action file
// Copyright (C) 2023 ZoneMinder Inc
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
global $error_message;
// Event scope actions, view permissions only required
if (!canView('Events')) {
$error_message = 'You do not have permission to view Events.';
ZM\Warning($error_message);
return;
}
global $error_message;
if ($action == 'delete') {
if (!canEdit('System')) {
$error_message .= 'You do not have System Edit permissions, you cannot delete files.<br/>';
return;
} // end if canEdit(System)
$path = (!empty($_REQUEST['path'])) ? detaintPathAllowAbsolute($_REQUEST['path']) : ZM_DIR_EVENTS;
$is_ok_path = false;
foreach (ZM\Storage::find() as $storage) {
$rc = strstr($path, $storage->Path(), true);
if ((false !== $rc) and ($rc == '')) {
# Must be at the beginning
$is_ok_path = true;
}
}
$path_parts = pathinfo($path);
# $is_ok_path was computed above but never consulted, so a path outside every
# Storage area still reached unlink(). detaintPathAllowAbsolute() permits
# absolute paths, so this is what keeps the delete inside a Storage area.
if (!$is_ok_path) {
$error_message .= 'Path is not valid. Path must be below a designated Storage area.<br/>';
ZM\Warning("Refusing to delete files under '$path': not below a Storage area");
return;
}
foreach ($_REQUEST['files'] as $file) {
$full_path = $path.'/'.detaintPath($file);
if (is_file($full_path)) {
unlink($full_path);
} else {
ZM\Debug("$full_path is not a file");
$error_message .= 'We do not support deleting directories at this time.<br/>';
}
}
} // end if object == filter
?>