Skip to content

Commit c672a28

Browse files
security: fix unsafe deserialization in managers.php (1.2.x backport) (#6898)
Backport of develop PR #6895 to 1.2.x. Replace cacti_unserialize(stripslashes(get_nfilter_request_var(...))) with sanitize_unserialize_selected_items() at both call sites in managers.php. Add intval() cast on imploded IDs as defense-in-depth. The safe function validates serialized structure and ensures all values are numeric before use in SQL queries. Addresses: GHSA-j9jv-6xjq-9hhj Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent d16af49 commit c672a28

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

managers.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -915,22 +915,19 @@ function form_actions() {
915915

916916
if (isset_request_var('selected_items')) {
917917
if (isset_request_var('action_receivers')) {
918-
$selected_items = cacti_unserialize(stripslashes(get_nfilter_request_var('selected_graphs_array')));
918+
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_graphs_array'));
919919

920920
if ($selected_items !== false) {
921-
/* validate the selected items are ids */
922-
foreach($selected_items as $index => $id) {
923-
input_validate_input_number($id);
924-
}
921+
$ids = implode(',', array_map('intval', $selected_items));
925922

926923
if (get_nfilter_request_var('drp_action') == '1') { // delete
927-
db_execute('DELETE FROM snmpagent_managers WHERE id IN (' . implode(',' ,$selected_items) . ')');
928-
db_execute('DELETE FROM snmpagent_managers_notifications WHERE manager_id IN (' . implode(',' ,$selected_items) . ')');
929-
db_execute('DELETE FROM snmpagent_notifications_log WHERE manager_id IN (' . implode(',' ,$selected_items) . ')');
924+
db_execute('DELETE FROM snmpagent_managers WHERE id IN (' . $ids . ')');
925+
db_execute('DELETE FROM snmpagent_managers_notifications WHERE manager_id IN (' . $ids . ')');
926+
db_execute('DELETE FROM snmpagent_notifications_log WHERE manager_id IN (' . $ids . ')');
930927
} elseif (get_nfilter_request_var('drp_action') == '2') { // enable
931-
db_execute("UPDATE snmpagent_managers SET disabled = '' WHERE id IN (" . implode(',' ,$selected_items) . ')');
928+
db_execute("UPDATE snmpagent_managers SET disabled = '' WHERE id IN (" . $ids . ')');
932929
} elseif (get_nfilter_request_var('drp_action') == '3') { // disable
933-
db_execute("UPDATE snmpagent_managers SET disabled = 'on' WHERE id IN (" . implode(',' ,$selected_items) . ')');
930+
db_execute("UPDATE snmpagent_managers SET disabled = 'on' WHERE id IN (" . $ids . ')');
934931
}
935932

936933
header('Location: managers.php?header=false');
@@ -943,7 +940,7 @@ function form_actions() {
943940

944941
$selected_items = cacti_unserialize(stripslashes(get_nfilter_request_var('selected_items')));
945942

946-
if ($selected_items !== false) {
943+
if (is_array($selected_items)) {
947944
if (get_nfilter_request_var('drp_action') == '1') { // disable
948945
foreach($selected_items as $mib => $notifications) {
949946
foreach($notifications as $notification => $state) {

0 commit comments

Comments
 (0)