@@ -182,6 +182,12 @@ function syslog_apply_selected_items_action($selected_items, $drp_action, $actio
182182}
183183
184184function 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
0 commit comments