Skip to content

Commit beadd36

Browse files
fix: resolve code review findings
- Fix broken SQL in syslog_get_alert_sql: remove $uniqueID concatenation after ? placeholder (was producing ?42 instead of using bind param) - Fix XSS in setup.php: use json_encode with JSON_HEX_* flags for JS string context instead of __esc (HTML escaper) - Fix duplicate global $syslogdb_default in syslog_process_alerts - Parameterize retention DELETE queries in syslog_delete_records - Parameterize count query in syslog_remove_items Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 694fea1 commit beadd36

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

functions.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ function syslog_traditional_manage() {
174174
}
175175

176176
/* delete from the main syslog table first */
177-
syslog_db_execute_prepared("DELETE FROM `" . $syslogdb_default . "`.`syslog` WHERE logtime < '$retention'");
177+
syslog_db_execute_prepared("DELETE FROM `" . $syslogdb_default . "`.`syslog` WHERE logtime < ?", array($retention));
178178

179179
$syslog_deleted = db_affected_rows($syslog_cnn);
180180

181181
/* now delete from the syslog removed table */
182-
syslog_db_execute_prepared("DELETE FROM `" . $syslogdb_default . "`.`syslog_removed` WHERE logtime < '$retention'");
182+
syslog_db_execute_prepared("DELETE FROM `" . $syslogdb_default . "`.`syslog_removed` WHERE logtime < ?", array($retention));
183183

184184
$syslog_deleted += db_affected_rows($syslog_cnn);
185185

@@ -379,9 +379,9 @@ function syslog_remove_items($table, $uniqueID) {
379379
$xferred = 0;
380380

381381
if ($table == 'syslog_incoming') {
382-
$total = syslog_db_fetch_cell('SELECT count(*)
382+
$total = syslog_db_fetch_cell_prepared('SELECT count(*)
383383
FROM `' . $syslogdb_default . '`.`syslog_incoming`
384-
WHERE `status` = ' . $uniqueID);
384+
WHERE `status` = ?', array($uniqueID));
385385
} else {
386386
$total = 0;
387387
}
@@ -1172,7 +1172,6 @@ function syslog_array2xml($array, $tag = 'template') {
11721172
*/
11731173
function syslog_process_alerts($uniqueID) {
11741174
global $syslogdb_default;
1175-
global $syslogdb_default;
11761175

11771176
$syslog_alarms = 0;
11781177
$syslog_alerts = 0;
@@ -1736,15 +1735,15 @@ function syslog_get_alert_sql(&$alert, $uniqueID) {
17361735
$sql = 'SELECT *
17371736
FROM `' . $syslogdb_default . '`.`syslog_incoming`
17381737
WHERE `' . $syslog_incoming_config['hostField'] . '` = ?
1739-
AND `status` = ?' . $uniqueID;
1738+
AND `status` = ?';
17401739

17411740
$params[] = $alert['message'];
17421741
$params[] = $uniqueID;
17431742
} elseif ($alert['type'] == 'program') {
17441743
$sql = 'SELECT *
17451744
FROM `' . $syslogdb_default . '`.`syslog_incoming`
17461745
WHERE `' . $syslog_incoming_config['programField'] . '` = ?
1747-
AND `status` = ?' . $uniqueID;
1746+
AND `status` = ?';
17481747

17491748
$params[] = $alert['message'];
17501749
$params[] = $uniqueID;

setup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,21 +1652,21 @@ function syslog_utilities_list() {
16521652
$(function() {
16531653
$('#syslog_purge_hosts').on('click', function() {
16541654
$('#syslog_purge_dialog').dialog({
1655-
title: <?php print "'" . __esc('Confirm Purge', 'syslog') . "'";?>,
1655+
title: <?php print json_encode(__('Confirm Purge', 'syslog'), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);?>,
16561656
minHeight: 80,
16571657
minWidth: 400,
16581658
resizable: false,
16591659
draggable: true,
16601660
buttons: {
16611661
'Cancel': {
1662-
text: <?php print "'" . __esc('Cancel', 'syslog') . "'";?>,
1662+
text: <?php print json_encode(__('Cancel', 'syslog'), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);?>,
16631663
id: 'btnPurgeCancel',
16641664
click: function() {
16651665
$(this).dialog('close');
16661666
}
16671667
},
16681668
'Continue': {
1669-
text: <?php print "'" . __esc('Continue', 'syslog') . "'";?>,
1669+
text: <?php print json_encode(__('Continue', 'syslog'), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);?>,
16701670
id: 'btnPurgeContinue',
16711671
click: function() {
16721672
$(this).dialog('close');

0 commit comments

Comments
 (0)