Skip to content

Commit ecc5e78

Browse files
security: fix SSRF, command injection, and XSS in core functions (1.2.x)
- Validate URL in call_remote_data_collector to prevent SSRF via protocol/host injection - Escape database, username, password, and output_file in db_dump_data exec calls - Escape $title in html_start_box to prevent stored XSS Defense-in-depth: all three have limited exploitability (admin-only callers, DB-sourced inputs, or translated string titles) but are worth hardening. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent cea6212 commit ecc5e78

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/database.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,14 +2233,17 @@ function db_dump_data($database = '', $tables = '', $credentials = array(), $out
22332233
if (!isset($username)) {
22342234
$username = $database_username;
22352235
}
2236+
$safe_database = cacti_escapeshellarg($database);
2237+
$safe_output = cacti_escapeshellarg($output_file);
2238+
22362239
if (strstr($options, '--defaults-extra-file') !== false) {
2237-
exec("mysqldump $options $credentials_string $database $tables > " . $output_file, $output, $retval);
2240+
exec("mysqldump $options $credentials_string $safe_database $tables > " . $safe_output, $output, $retval);
22382241
} else {
2239-
exec("mysqldump $options $credentials_string " . $database . ' version >/dev/null 2>&1', $output, $retval);
2242+
exec("mysqldump $options $credentials_string " . $safe_database . ' version >/dev/null 2>&1', $output, $retval);
22402243
if ($retval) {
2241-
exec("mysqldump $options $credentials_string -u" . $username . ' -p' . $password . ' ' . $database . " $tables > " . $output_file, $output, $retval);
2244+
exec("mysqldump $options $credentials_string -u" . cacti_escapeshellarg($username) . ' -p' . cacti_escapeshellarg($password) . ' ' . $safe_database . " $tables > " . $safe_output, $output, $retval);
22422245
} else {
2243-
exec("mysqldump $options $credentials_string $database $tables > " . $output_file, $output, $retval);
2246+
exec("mysqldump $options $credentials_string $safe_database $tables > " . $safe_output, $output, $retval);
22442247
}
22452248
}
22462249
return $retval;

lib/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6254,6 +6254,12 @@ function call_remote_data_collector($poller_id, $url, $logtype = 'WEBUI') {
62546254
}
62556255
}
62566256

6257+
// Validate URL is a relative path to prevent SSRF
6258+
if (strpos($url, '://') !== false || strpos($url, '@') !== false) {
6259+
cacti_log('ERROR: Invalid URL passed to call_remote_data_collector: ' . $url, false, 'SECURITY');
6260+
return '';
6261+
}
6262+
62576263
$fgc_contextoption = get_default_contextoption();
62586264
$fgc_context = stream_context_create($fgc_contextoption);
62596265

lib/html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function html_start_box($title, $width, $div, $cell_padding, $align, $add_text,
101101
if ($title != '') {
102102
print "<div id='$table_id' class='cactiTable' style='width:$width;text-align:$align;'>";
103103
print '<div>';
104-
print "<div class='cactiTableTitle'><span>" . ($title != '' ? $title:'') . '</span></div>';
104+
print "<div class='cactiTableTitle'><span>" . ($title != '' ? html_escape($title):'') . '</span></div>';
105105
print "<div class='cactiTableButton'>";
106106

107107
$page = get_current_page();

0 commit comments

Comments
 (0)