Skip to content

Commit b0ac9a9

Browse files
Fix missing authorization checks in AJAX endpoints and module actions
1 parent 66f6e76 commit b0ac9a9

11 files changed

Lines changed: 133 additions & 2 deletions

File tree

ajax/deleteActivity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
die();
3939
}
4040

41+
if ($_SESSION['CATS']->getAccessLevel('contacts.deleteActivity') < ACCESS_LEVEL_EDIT)
42+
{
43+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
44+
die();
45+
}
46+
4147
if (!$interface->isRequiredIDValid('activityID'))
4248
{
4349
$interface->outputXMLErrorPage(-1, 'Invalid activity ID.');

ajax/editActivity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
die();
4242
}
4343

44+
if ($_SESSION['CATS']->getAccessLevel('contacts.editActivity') < ACCESS_LEVEL_EDIT)
45+
{
46+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
47+
die();
48+
}
49+
4450
if (!$interface->isRequiredIDValid('activityID'))
4551
{
4652
$interface->outputXMLErrorPage(-1, 'Invalid activity ID.');

ajax/testEmailSettings.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
die();
3939
}
4040

41+
if ($_SESSION['CATS']->getAccessLevel('settings.emailSettings.POST') < ACCESS_LEVEL_SA)
42+
{
43+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
44+
die();
45+
}
46+
4147
$siteID = $interface->getSiteID();
4248

4349
if (!isset($_POST['testEmailAddress']) ||

lib/Calendar.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,32 @@ public function getAllEventTypes()
270270
return $this->_db->getAllAssoc($sql);
271271
}
272272

273+
/**
274+
* Returns a calendar event.
275+
*
276+
* @param integer Calendar Event ID.
277+
* @return array Calendar event data array, or empty array if no record
278+
* is present.
279+
*/
280+
public function get($eventID)
281+
{
282+
$sql = sprintf(
283+
"SELECT
284+
calendar_event.calendar_event_id AS eventID,
285+
calendar_event.entered_by AS enteredBy
286+
FROM
287+
calendar_event
288+
WHERE
289+
calendar_event.calendar_event_id = %s
290+
AND
291+
calendar_event.site_id = %s",
292+
$this->_db->makeQueryInteger($eventID),
293+
$this->_siteID
294+
);
295+
296+
return $this->_db->getAssoc($sql);
297+
}
298+
273299
/**
274300
* Adds a calendar event to the database.
275301
*

modules/calendar/CalendarUI.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,19 @@ private function onEditEvent()
582582

583583
$eventID = $_POST['eventID'];
584584
$type = $_POST['type'];
585+
$calendar = new Calendar($this->_siteID);
586+
$eventRS = $calendar->get($eventID);
587+
588+
if (empty($eventRS))
589+
{
590+
CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid event ID.');
591+
}
592+
593+
if ($eventRS['enteredBy'] != $this->_userID &&
594+
$this->getUserAccessLevel('calendar.show') < ACCESS_LEVEL_SA)
595+
{
596+
CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
597+
}
585598

586599
if ($_POST['allDay'] == 1)
587600
{
@@ -662,7 +675,6 @@ private function onEditEvent()
662675
if (!eval(Hooks::get('CALENDAR_EDIT_PRE'))) return;
663676

664677
/* Update the event. */
665-
$calendar = new Calendar($this->_siteID);
666678
if (!$calendar->updateEvent($eventID, $type, $date, $description,
667679
$allDay, $dataItemID, $dataItemType, 'NULL', $title, $duration,
668680
$reminderEnabled, $reminderEmail, $reminderTime, $publicEntry,
@@ -711,10 +723,22 @@ private function onDeleteEvent()
711723
}
712724

713725
$eventID = $_POST['eventID'];
726+
$calendar = new Calendar($this->_siteID);
727+
$eventRS = $calendar->get($eventID);
728+
729+
if (empty($eventRS))
730+
{
731+
CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid event ID.');
732+
}
733+
734+
if ($eventRS['enteredBy'] != $this->_userID &&
735+
$this->getUserAccessLevel('calendar.show') < ACCESS_LEVEL_SA)
736+
{
737+
CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
738+
}
714739

715740
if (!eval(Hooks::get('CALENDAR_DELETE_PRE'))) return;
716741

717-
$calendar = new Calendar($this->_siteID);
718742
$calendar->deleteEvent($eventID);
719743

720744
if (!eval(Hooks::get('CALENDAR_DELETE_POST'))) return;

modules/import/ImportUI.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public function handleRequest()
154154
*/
155155
private function revert()
156156
{
157+
if ($this->getUserAccessLevel('import.import') < ACCESS_LEVEL_EDIT)
158+
{
159+
CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
160+
}
161+
157162
if (!$this->isRequiredIDValid('importID', $_POST))
158163
{
159164
$this->import();

modules/lists/ajax/addToLists.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function isRequiredValueValid($value)
6868
die();
6969
}
7070

71+
if ($_SESSION['CATS']->getAccessLevel('lists') < ACCESS_LEVEL_EDIT)
72+
{
73+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
74+
die();
75+
}
76+
7177
if (!isset($_POST['listsToAdd']))
7278
{
7379
$interface->outputXMLErrorPage(-1, 'No listsToAdd passed.');

modules/lists/ajax/deleteList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
die();
4242
}
4343

44+
if ($_SESSION['CATS']->getAccessLevel('lists') < ACCESS_LEVEL_EDIT)
45+
{
46+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
47+
die();
48+
}
49+
4450
if (!isset($_POST['savedListID']) || !ctype_digit((string) $_POST['savedListID']))
4551
{
4652
$interface->outputXMLErrorPage(-1, 'Invalid saved list ID.');

modules/lists/ajax/editListName.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
die();
4242
}
4343

44+
if ($_SESSION['CATS']->getAccessLevel('lists') < ACCESS_LEVEL_EDIT)
45+
{
46+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
47+
die();
48+
}
49+
4450
if (!isset($_POST['savedListID']) || !ctype_digit((string) $_POST['savedListID']))
4551
{
4652
$interface->outputXMLErrorPage(-1, 'Invalid saved list ID.');

modules/lists/ajax/newList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
die();
4242
}
4343

44+
if ($_SESSION['CATS']->getAccessLevel('lists') < ACCESS_LEVEL_EDIT)
45+
{
46+
$interface->outputXMLErrorPage(-1, ERROR_NO_PERMISSION);
47+
die();
48+
}
49+
4450
if (!isset($_POST['dataItemType']) || !ctype_digit((string) $_POST['dataItemType']))
4551
{
4652
$interface->outputXMLErrorPage(-1, 'Invalid saved list type.');

0 commit comments

Comments
 (0)