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>
177 lines
4.7 KiB
PHP
177 lines
4.7 KiB
PHP
<?php
|
|
App::uses('AppController', 'Controller');
|
|
/**
|
|
* Zones Controller
|
|
*
|
|
* @property Zone $Zone
|
|
*/
|
|
class ZonesController extends AppController {
|
|
|
|
/**
|
|
* Components
|
|
*
|
|
* @var array
|
|
*/
|
|
public $components = array('RequestHandler');
|
|
|
|
public function beforeFilter() {
|
|
parent::beforeFilter();
|
|
|
|
global $user;
|
|
$canView = (!$user) || ($user->Monitors() != 'None');
|
|
if ( !$canView ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Find all zones which belong to a MonitorId
|
|
public function forMonitor($id = null) {
|
|
$this->loadModel('Monitor');
|
|
if ( !$this->Monitor->exists($id) ) {
|
|
throw new NotFoundException(__('Invalid monitor'));
|
|
}
|
|
|
|
# Monitors=View is coarse. Enforce the per-monitor ACL so zones of a monitor
|
|
# the user is denied are not listed by direct monitor Id.
|
|
$this->Monitor->recursive = -1;
|
|
$monitor = $this->Monitor->find('first', array(
|
|
'conditions' => array('Monitor.Id' => $id)
|
|
));
|
|
$MonitorObj = new ZM\Monitor($monitor['Monitor']);
|
|
if ( !$MonitorObj->canView() ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
|
|
$this->Zone->recursive = -1;
|
|
$zones = $this->Zone->find('all', array(
|
|
'conditions' => array('MonitorId' => $id)
|
|
));
|
|
$this->set(array(
|
|
'zones' => $zones,
|
|
'_serialize' => array('zones')
|
|
));
|
|
}
|
|
|
|
public function index() {
|
|
$this->Zone->recursive = -1;
|
|
|
|
global $user;
|
|
$allowedMonitors = ($user and $user->unviewableMonitorIds()) ? $user->viewableMonitorIds() : [];
|
|
if (count($allowedMonitors)) {
|
|
$mon_options = array('Zones.MonitorId' => $allowedMonitors);
|
|
} else {
|
|
$mon_options = '';
|
|
}
|
|
$zones = $this->Zone->find('all',$mon_options);
|
|
$this->set(array(
|
|
'zones' => $zones,
|
|
'_serialize' => array('zones')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* add method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function add() {
|
|
|
|
if ( !$this->request->is('post') ) {
|
|
throw new BadRequestException(__('Invalid method. Should be post'));
|
|
return;
|
|
}
|
|
|
|
global $user;
|
|
$canEdit = (!$user) || $user->Monitors() == 'Edit' || $user->Monitors() == 'Create';
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
|
|
$zone = null;
|
|
|
|
$this->Zone->create();
|
|
$zone = $this->Zone->save($this->request->data);
|
|
if ( $zone ) {
|
|
require_once __DIR__ .'/../../../includes/Monitor.php';
|
|
$monitor = new ZM\Monitor($zone['Zone']['MonitorId']);
|
|
$monitor->zmcControl('restart');
|
|
$message = 'Saved';
|
|
//$zone = $this->Zone->find('first', array('conditions' => array( array('Zone.' . $this->Zone->primaryKey => $this->Zone),
|
|
} else {
|
|
$message = 'Error: ';
|
|
// if there is a validation message, use it
|
|
if ( !$this->Zone->validates() ) {
|
|
$message = $this->Zone->validationErrors;
|
|
}
|
|
}
|
|
|
|
$this->set(array(
|
|
'message' => $message,
|
|
'zone' => $zone,
|
|
'_serialize' => array('message','zone')
|
|
));
|
|
} // end function add()
|
|
|
|
/**
|
|
* edit method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function edit($id = null) {
|
|
$this->Zone->id = $id;
|
|
|
|
if ( !$this->Zone->exists($id) ) {
|
|
throw new NotFoundException(__('Invalid zone'));
|
|
}
|
|
$message = '';
|
|
if ( $this->request->is(array('post', 'put')) ) {
|
|
global $user;
|
|
$canEdit = (!$user) || $user->Monitors() == 'Edit' || $user->Monitors() == 'Create';
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
if ( $this->Zone->save($this->request->data) ) {
|
|
$message = 'The zone has been saved.';
|
|
} else {
|
|
$message = 'Error ' . print_r($this->Zone->invalidFields());
|
|
}
|
|
}
|
|
$this->set(array(
|
|
'message' => $message,
|
|
'_serialize' => array('message')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* delete method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function delete($id = null) {
|
|
$this->Zone->id = $id;
|
|
if ( !$this->Zone->exists() ) {
|
|
throw new NotFoundException(__('Invalid zone'));
|
|
}
|
|
$this->request->allowMethod('post', 'delete');
|
|
global $user;
|
|
$canEdit = (!$user) || $user->Monitors() == 'Edit' || $user->Monitors() == 'Create';
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
if ( $this->Zone->delete() ) {
|
|
return $this->flash(__('The zone has been deleted.'), array('action' => 'index'));
|
|
} else {
|
|
return $this->flash(__('The zone could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
}
|
|
}
|
|
} // end class
|