mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-09-13 05:38:05 -04:00
EventDataController and TagsController both authorized only with the account-wide Events permission in beforeFilter() (Events != None) and never applied the per-monitor ACL that EventsController resolves via unviewableMonitorIds()/viewableMonitorIds(). A monitor-restricted account could therefore read data belonging to cameras it is explicitly denied. EventDataController::index() and ::view() now filter on Event_Data.MonitorId (the table carries its own MonitorId, so the restriction applies directly, mirroring EventsController's Event.MonitorId filter). ::view() returns 403 when the row exists but is outside the caller's allowed monitors, matching EventsController. ::edit() and ::delete() now go through requireEventDataEdit(), which requires Events=Edit plus the per-monitor ACL on the target row, so a restricted or view-only account cannot mutate or delete another monitor's event data by Id. The pre-existing view/edit reads also stop hardcoding a "Event_Data." alias prefix that does not match the model alias, using $this->EventData->alias instead. TagsController exposes per-monitor data only where a tag is joined to its events: index() filtered by Events.Id (returns Events_Tags.EventId) and associations() (contains each tag's Events). Both now restrict the joined Events to viewable monitors when the caller is monitor-restricted. The plain tag list is a global label vocabulary shared across monitors and is left unrestricted so restricted users can still tag their own events. This is the same defect class as GHSA-mg2g-jmfc-3w8g (FramesController), reported here as GHSA-rgwp-wvjw-6925 for EventDataController; the Tags controller was found to share the shape during the audit the report suggested. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
171 lines
5.2 KiB
PHP
171 lines
5.2 KiB
PHP
<?php
|
|
App::uses('AppController', 'Controller');
|
|
/**
|
|
* EventData Controller
|
|
*
|
|
* @property EventData $EventData
|
|
*/
|
|
class EventDataController extends AppController {
|
|
|
|
/**
|
|
* Components
|
|
*
|
|
* @var array
|
|
*/
|
|
public $components = array('RequestHandler');
|
|
|
|
public function beforeFilter() {
|
|
parent::beforeFilter();
|
|
global $user;
|
|
# We already tested for auth in appController, so we just need to test for specific permission
|
|
$canView = (!$user) || ($user->Events() != 'None');
|
|
if (!$canView) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
}
|
|
|
|
# Event_Data mutation requires Events=Edit (beforeFilter only guarantees
|
|
# Events != None) plus the per-monitor ACL on the row being changed, so a
|
|
# user denied a monitor cannot alter that monitor's event data by Id.
|
|
private function requireEventDataEdit($id) {
|
|
global $user;
|
|
if ( $user and ($user->Events() != 'Edit') ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
$allowedMonitors = ($user and $user->unviewableMonitorIds()) ? $user->viewableMonitorIds() : null;
|
|
if ( $allowedMonitors !== null ) {
|
|
$this->EventData->recursive = -1;
|
|
$row = $this->EventData->find('first', array(
|
|
'conditions' => array($this->EventData->alias.'.'.$this->EventData->primaryKey => $id),
|
|
));
|
|
$monitorId = $row ? $row[$this->EventData->alias]['MonitorId'] : null;
|
|
if ( !in_array($monitorId, $allowedMonitors) ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* index method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function index() {
|
|
$this->EventData->recursive = -1;
|
|
if ( $this->request->params['named'] ) {
|
|
$this->FilterComponent = $this->Components->load('Filter');
|
|
$conditions = $this->FilterComponent->buildFilter($this->request->params['named']);
|
|
} else {
|
|
$conditions = array();
|
|
}
|
|
|
|
# Event_Data carries its own MonitorId, so the per-monitor ACL that
|
|
# EventsController applies via Event.MonitorId can be applied directly here.
|
|
# Without it any user with Events != None reads event data for cameras they
|
|
# are explicitly denied.
|
|
global $user;
|
|
$allowedMonitors = ($user and $user->unviewableMonitorIds()) ? $user->viewableMonitorIds() : array();
|
|
if ( count($allowedMonitors) ) {
|
|
$conditions[] = array($this->EventData->alias.'.MonitorId' => $allowedMonitors);
|
|
}
|
|
|
|
$find_array = array(
|
|
'conditions' => &$conditions,
|
|
);
|
|
$event_data = $this->EventData->find('all', $find_array);
|
|
$this->set(array(
|
|
'event_data' => $event_data,
|
|
'_serialize' => array('event_data')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* view method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function view($id = null) {
|
|
$this->EventData->recursive = -1;
|
|
if (!$this->EventData->exists($id)) {
|
|
throw new NotFoundException(__('Invalid event data'));
|
|
}
|
|
global $user;
|
|
$allowedMonitors = ($user and $user->unviewableMonitorIds()) ? $user->viewableMonitorIds() : array();
|
|
$conditions = array($this->EventData->alias.'.'.$this->EventData->primaryKey => $id);
|
|
if ( count($allowedMonitors) ) {
|
|
$conditions[$this->EventData->alias.'.MonitorId'] = $allowedMonitors;
|
|
}
|
|
$event_data = $this->EventData->find('first', array('conditions' => $conditions));
|
|
if ( !$event_data ) {
|
|
# exists() above proved the row is present, so an empty result here means
|
|
# the per-monitor ACL filtered it out: the caller is denied this monitor.
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
$this->set(array(
|
|
'event_data' => $event_data,
|
|
'_serialize' => array('event_data')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* add method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function add() {
|
|
if ($this->request->is('post')) {
|
|
$this->EventData->create();
|
|
if ($this->EventData->save($this->request->data)) {
|
|
}
|
|
}
|
|
$events = $this->EventData->Event->find('list');
|
|
$this->set(compact('events'));
|
|
}
|
|
|
|
/**
|
|
* edit method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function edit($id = null) {
|
|
if (!$this->EventData->exists($id)) {
|
|
throw new NotFoundException(__('Invalid event_data'));
|
|
}
|
|
$this->requireEventDataEdit($id);
|
|
if ($this->request->is(array('post', 'put'))) {
|
|
if ($this->EventData->save($this->request->data)) {
|
|
}
|
|
} else {
|
|
$options = array('conditions' => array($this->EventData->alias.'.'.$this->EventData->primaryKey => $id));
|
|
$this->request->data = $this->EventData->find('first', $options);
|
|
}
|
|
$events = $this->EventData->Event->find('list');
|
|
$this->set(compact('events'));
|
|
}
|
|
|
|
/**
|
|
* delete method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function delete($id = null) {
|
|
$this->EventData->id = $id;
|
|
if (!$this->EventData->exists()) {
|
|
throw new NotFoundException(__('Invalid event_data'));
|
|
}
|
|
$this->request->allowMethod('post', 'delete');
|
|
$this->requireEventDataEdit($id);
|
|
if ($this->EventData->delete()) {
|
|
return $this->flash(__('The event_data has been deleted.'), array('action' => 'index'));
|
|
} else {
|
|
return $this->flash(__('The event_data could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
}
|
|
}}
|