From f9a39ce99f806e495a522e6a35e89ddea8bf2b9e Mon Sep 17 00:00:00 2001 From: Jash Ambaliya <87864439+AJ0070@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:35:00 +0530 Subject: [PATCH] fix: alarm ajax reads id and command only when they are sent refs #8011 (#8012) --- tests/php/test_ajax_alarm_missing_params.php | 73 ++++++++++++++++++++ web/ajax/alarm.php | 6 +- 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 tests/php/test_ajax_alarm_missing_params.php diff --git a/tests/php/test_ajax_alarm_missing_params.php b/tests/php/test_ajax_alarm_missing_params.php new file mode 100644 index 0000000000..3626c3b991 --- /dev/null +++ b/tests/php/test_ajax_alarm_missing_params.php @@ -0,0 +1,73 @@ +getMessage(); + } catch (ErrorException $e) { + $error = $e->getMessage(); + } + + check("no ErrorException about an undefined array key", is_null($error), true); + check("request without parameters reaches ajaxError", $msg, 'Insufficient permissions'); + + @unlink($tmp.'/includes/Monitor.php'); + @rmdir($tmp.'/includes'); + @rmdir($tmp); + + echo "\n".($failures ? "FAILURES: $failures\n" : "All passed\n"); + exit($failures ? 1 : 0); +} diff --git a/web/ajax/alarm.php b/web/ajax/alarm.php index 41581983c9..371384942c 100644 --- a/web/ajax/alarm.php +++ b/web/ajax/alarm.php @@ -3,13 +3,13 @@ define('MSG_TIMEOUT', 2.0); define('MSG_DATA_SIZE', 4+256); require_once('includes/Monitor.php'); -$monitor = new ZM\Monitor(validCardinal($_REQUEST['id'])); +$monitor = new ZM\Monitor(validCardinal($_REQUEST['id'] ?? 0)); // Needs edit on this monitor, not only the global Monitors permission. if ( $monitor->Id() and $monitor->canEdit() ) { $zmuCommand = getZmuCommand(' -m '.$monitor->Id()); - switch ( validJsStr($_REQUEST['command']) ) { + switch ( validJsStr($_REQUEST['command'] ?? '') ) { case 'disableAlarms' : $zmuCommand .= ' -n'; break; @@ -23,7 +23,7 @@ if ( $monitor->Id() and $monitor->canEdit() ) { $zmuCommand .= ' -c'; break; default : - ajaxError("Unexpected command '".validJsStr($_REQUEST['command'])."'"); + ajaxError("Unexpected command '".validJsStr($_REQUEST['command'] ?? '')."'"); } $output = array(); $rc = 0;