Skip to content

Commit beced7b

Browse files
fix: file-size guard on XML import; parameterize seq IN-list with array_map/implode
Signed-off-by: Thomas Vincent <[email protected]>
1 parent 7a61b76 commit beced7b

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

functions.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ function syslog_apply_selected_items_action($selected_items, $drp_action, $actio
182182
}
183183

184184
function syslog_get_import_xml_payload($redirect_url) {
185+
/* Reject non-relative redirect targets to prevent open redirect.
186+
All legitimate callers pass a relative path (e.g. syslog_removal.php?header=false). */
187+
if (preg_match('/^(?:[a-z][a-z\d+\-.]*:|\/{2})/i', $redirect_url)) {
188+
$redirect_url = 'index.php';
189+
}
190+
185191
if (trim(get_nfilter_request_var('import_text')) != '') {
186192
/* textbox input */
187193
return get_nfilter_request_var('import_text');
@@ -203,6 +209,12 @@ function syslog_get_import_xml_payload($redirect_url) {
203209
exit;
204210
}
205211

212+
if ($_FILES['import_file']['size'] > 1048576) {
213+
cacti_log('SYSLOG ERROR: Uploaded import file exceeds 1 MB limit', false, 'SYSTEM');
214+
header('Location: ' . $redirect_url);
215+
exit;
216+
}
217+
206218
$fp = fopen($tmp_name, 'rb');
207219

208220
if ($fp === false) {
@@ -415,6 +427,16 @@ function syslog_partition_remove($table) {
415427
while ($user_partitions > $days) {
416428
$oldest = $number_of_partitions[$i];
417429

430+
/* PARTITION_NAME comes from information_schema, but validate the
431+
format before DDL interpolation — MySQL does not support parameter
432+
binding for DDL statements. */
433+
if (!preg_match('/^d\d{8}$/', $oldest['PARTITION_NAME'])) {
434+
cacti_log("SYSLOG ERROR: Unexpected partition name format '" . $oldest['PARTITION_NAME'] . "' for table '$table', skipping", false, 'SYSTEM');
435+
$i++;
436+
$user_partitions--;
437+
continue;
438+
}
439+
418440
cacti_log("SYSLOG: Removing old partition '" . $oldest['PARTITION_NAME'] . "' from table '$table'", false, 'SYSTEM');
419441

420442
syslog_debug("Removing partition '" . $oldest['PARTITION_NAME'] . "' from table '$table'");
@@ -926,13 +948,8 @@ function syslog_manage_items($from_table, $to_table) {
926948
syslog_debug(sprintf('Found %5s - Message(s)', cacti_sizeof($move_records)));
927949

928950
if (cacti_sizeof($move_records)) {
929-
$all_seq = '';
930951
$messages_moved = 0;
931-
foreach($move_records as $move_record) {
932-
$all_seq = $all_seq . ", " . $move_record['seq'];
933-
}
934-
935-
$all_seq = preg_replace('/^,/i', '', $all_seq);
952+
$all_seq = implode(',', array_map('intval', array_column($move_records, 'seq')));
936953
syslog_db_execute_prepared("INSERT INTO `". $syslogdb_default . "`.`". $to_table ."`
937954
(facility_id, priority_id, host_id, logtime, message)
938955
(SELECT facility_id, priority_id, host_id, logtime, message

tests/regression/issue252_xss_output_test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
exit(1);
2626
}
2727

28+
$alertsPhp = file_get_contents(dirname(__DIR__, 2) . '/syslog_alerts.php');
29+
30+
if ($alertsPhp === false) {
31+
fwrite(STDERR, "Failed to load syslog_alerts.php for issue252 checks.\n");
32+
exit(1);
33+
}
34+
35+
if (strpos($alertsPhp, "html_escape(\$alert_info)") === false) {
36+
fwrite(STDERR, "Expected escaped alert confirmation list entries.\n");
37+
exit(1);
38+
}
39+
2840
if (strpos($reportsPhp, "form_selectable_ecell(\$report['message'], \$report['id']);") === false) {
2941
fwrite(STDERR, "Expected escaped report message cell rendering.\n");
3042
exit(1);

0 commit comments

Comments
 (0)