mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-08-03 16:52:36 -04:00
Several API endpoints checked only the coarse Events/Monitors permission and not the per-monitor object ACL, so a user explicitly denied a monitor could still reach that monitor's objects by addressing them directly: - EventsController::edit() and ::delete() checked Events=Edit but never called canEdit() on the event, so any event could be mutated or deleted by Id. - FramesController only guaranteed Events != None in beforeFilter(). view() returned any frame by Id, and edit()/delete() mutated frames without requiring Events=Edit or checking the parent event at all. - ZonesController::forMonitor() listed zones for any monitor Id. Resolve the owning object and apply the same canView()/canEdit() checks the normal read paths already use. Frames are addressed by their own Id, so their parent event is looked up to reach the monitor ACL. Refs GHSA-hw39-qpjw-p7cg. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
175 lines
4.8 KiB
PHP
175 lines
4.8 KiB
PHP
<?php
|
|
App::uses('AppController', 'Controller');
|
|
/**
|
|
* Frames Controller
|
|
*
|
|
* @property Frame $Frame
|
|
*/
|
|
class FramesController 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;
|
|
}
|
|
}
|
|
|
|
# Frames are addressed by their own Id, so the parent Event's per-monitor ACL
|
|
# has to be resolved explicitly. Without this a user denied a monitor can
|
|
# reach that monitor's frames by guessing frame Ids.
|
|
private function eventForFrame($id) {
|
|
$this->Frame->recursive = -1;
|
|
$frame = $this->Frame->find('first', array(
|
|
'conditions' => array('Frame.' . $this->Frame->primaryKey => $id)
|
|
));
|
|
if (!$frame) {
|
|
throw new NotFoundException(__('Invalid frame'));
|
|
}
|
|
$this->loadModel('Event');
|
|
$this->Event->recursive = -1;
|
|
$event = $this->Event->find('first', array(
|
|
'conditions' => array('Event.Id' => $frame['Frame']['EventId'])
|
|
));
|
|
if (!$event) {
|
|
throw new NotFoundException(__('Invalid event'));
|
|
}
|
|
return new ZM\Event($event['Event']);
|
|
}
|
|
|
|
# Frame mutation is an Event mutation, so require Events=Edit as well as the
|
|
# per-monitor ACL. beforeFilter() only guarantees Events != None.
|
|
private function requireFrameEdit($id) {
|
|
global $user;
|
|
if ($user and ($user->Events() != 'Edit')) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
if (!$this->eventForFrame($id)->canEdit()) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* index method
|
|
* @return void
|
|
*/
|
|
public function index() {
|
|
$this->Frame->recursive = -1;
|
|
|
|
global $user;
|
|
$allowedMonitors = ($user and $user->unviewableMonitorIds()) ? $user->viewableMonitorIds() : null;
|
|
if ( $allowedMonitors ) {
|
|
$mon_options = array('Event.MonitorId' => $allowedMonitors);
|
|
} else {
|
|
$mon_options = '';
|
|
}
|
|
$named_params = $this->request->params['named'];
|
|
if ( $named_params ) {
|
|
$this->FilterComponent = $this->Components->load('Filter');
|
|
$conditions = $this->FilterComponent->buildFilter($named_params);
|
|
} else {
|
|
$conditions = array();
|
|
}
|
|
|
|
$frames = $this->Frame->find('all', ['conditions'=>$conditions]);
|
|
$this->set(array(
|
|
'frames' => $frames,
|
|
'_serialize' => array('frames')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* view method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function view($id = null) {
|
|
$this->Frame->recursive = -1;
|
|
if (!$this->Frame->exists($id)) {
|
|
throw new NotFoundException(__('Invalid frame'));
|
|
}
|
|
if (!$this->eventForFrame($id)->canView()) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
}
|
|
$options = array('conditions' => array('Frame.' . $this->Frame->primaryKey => $id));
|
|
$frame = $this->Frame->find('first', $options);
|
|
$this->set(array(
|
|
'frame' => $frame,
|
|
'_serialize' => array('frame')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* add method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function add() {
|
|
if ($this->request->is('post')) {
|
|
$this->Frame->create();
|
|
if ($this->Frame->save($this->request->data)) {
|
|
return $this->flash(__('The frame has been saved.'), array('action' => 'index'));
|
|
}
|
|
}
|
|
$events = $this->Frame->Event->find('list');
|
|
$this->set(compact('events'));
|
|
}
|
|
|
|
/**
|
|
* edit method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function edit($id = null) {
|
|
if (!$this->Frame->exists($id)) {
|
|
throw new NotFoundException(__('Invalid frame'));
|
|
}
|
|
$this->requireFrameEdit($id);
|
|
if ($this->request->is(array('post', 'put'))) {
|
|
if ($this->Frame->save($this->request->data)) {
|
|
return $this->flash(__('The frame has been saved.'), array('action' => 'index'));
|
|
}
|
|
} else {
|
|
$options = array('conditions' => array('Frame.' . $this->Frame->primaryKey => $id));
|
|
$this->request->data = $this->Frame->find('first', $options);
|
|
}
|
|
$events = $this->Frame->Event->find('list');
|
|
$this->set(compact('events'));
|
|
}
|
|
|
|
/**
|
|
* delete method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function delete($id = null) {
|
|
$this->Frame->id = $id;
|
|
if (!$this->Frame->exists()) {
|
|
throw new NotFoundException(__('Invalid frame'));
|
|
}
|
|
$this->request->allowMethod('post', 'delete');
|
|
$this->requireFrameEdit($id);
|
|
if ($this->Frame->delete()) {
|
|
return $this->flash(__('The frame has been deleted.'), array('action' => 'index'));
|
|
} else {
|
|
return $this->flash(__('The frame could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
}
|
|
}}
|