Files
zoneminder/web/includes/actions/snapshot.php
T
Isaac ConnorandClaude Opus 5.5 c3d2e542bc fix: never build an object from an id the request sent as an array
ZM_Object's constructor treats an array as the object's row, and validInt()
and validCardinal() returned an array as they got it (preg_replace() does).
So wherever a request id reached `new ZM\X(...)`, raw or through those
validators, a crafted array built an object whose Id, UserId or MonitorId
the sender chose. The permission check then looked at those, and the delete
or update that followed used the Id. A user with Events=View deleted another
user's filter by posting Id[Id]=<filter>&Id[UserId]=<self> to the filter
delete action; the same shape reached events (MonitorId), users, reports,
snapshots and storage.

validInt() and validCardinal() now give '' for anything that isn't a single
value. The places that built an object from a raw $_REQUEST value (the
control and event ajax handlers, the event, filter, report, snapshot and
storage actions, view_hls, and the download and event detail modals) take
the id through validCardinal().

tests/php/test_request_ids_scalar.php covers the validators with arrays and
fails if web code builds an object straight from $_REQUEST, $_GET or $_POST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 23:07:08 -04:00

90 lines
3.0 KiB
PHP

<?php
//
// ZoneMinder web action
// Copyright (C) 2019 ZoneMinder LLC
//
// 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.
//
require_once('includes/Snapshot.php');
require_once('includes/Monitor.php');
if ( $action == 'create' ) {
if ( ! (isset($_REQUEST['monitor_ids']) and count($_REQUEST['monitor_ids']) > 0 ) ) {
ZM\Error('No monitor ids given in snapshot creation request');
return;
}
$snapshot = new ZM\Snapshot();
$snapshot->save(array('CreatedBy'=>$user->Id()));
ZM\AuditAction('create', 'snapshot', $snapshot->Id(), '');
foreach ( $_REQUEST['monitor_ids'] as $monitor_id ) {
if (!validCardinal($monitor_id)) {
Error("Monitor Id value is invalid $monitor_id");
continue;
}
$monitor = ZM\Monitor::find_one(['Id'=>$monitor_id]);
if (!$monitor) {
Error("Monitor not found for id $monitor_id");
continue;
}
$snapshot_event = new ZM\Snapshot_Event();
$event_id = $monitor->TriggerOn();
ZM\Debug("Have event $event_id for monitor $monitor_id");
if ( $event_id ) {
$snapshot_event->save(array(
'SnapshotId'=>$snapshot->Id(),
'EventId'=>$event_id
));
}
} # end foreach monitor
foreach ( $_REQUEST['monitor_ids'] as $monitor_id ) {
$monitor = ZM\Monitor::find_one(['Id'=>$monitor_id]);
if (!$monitor) continue;
$monitor->TriggerOff();
}
$dbConn->beginTransaction();
foreach ( $snapshot->Events() as $event ) {
$event->lock();
$event->save(array('Archived'=>1));
}
$dbConn->commit();
$redirect = '?view=snapshot&id='.$snapshot->Id();
return;
}
// Event scope actions, view permissions only required
if ( isset($_REQUEST['id']) ) {
$snapshot = new ZM\Snapshot(validCardinal($_REQUEST['id']));
if ( ($action == 'save') ) {
if ( canEdit('Events') or $snapshot->CreatedBy() == $user->Id() ) {
$changes = $snapshot->changes($_REQUEST['snapshot']);
if ( count($changes) ) {
$snapshot->save($changes);
ZM\AuditAction('update', 'snapshot', $snapshot->Id(), 'Changed: '.implode(', ', array_keys($changes)));
}
$redirect = '?view=snapshots';
}
} else if ( $action == 'delete' ) {
if ( canEdit('Events') ) {
$snapshot->delete();
ZM\AuditAction('delete', 'snapshot', $_REQUEST['id'], '');
$redirect = '?view=snapshots';
}
}
} // end if canEdit(Events)
?>