security: fix SSRF, command injection, and XSS in core functions (1.2.x)#6913
Merged
TheWitness merged 5 commits intoCacti:1.2.xfrom Mar 29, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Defense-in-depth security hardening across core Cacti helpers to reduce risk of stored XSS, SSRF-style URL authority injection, and shell command injection in mysqldump execution paths.
Changes:
- Escape
html_start_box()title output to mitigate stored XSS. - Add URL validation in
call_remote_data_collector()to restrict unsafe inputs. - Shell-escape mysqldump arguments in
db_dump_data().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/html.php | Escapes html_start_box() title output. |
| lib/functions.php | Adds URL validation before remote collector file_get_contents(). |
| lib/database.php | Escapes selected mysqldump arguments before exec(). |
- 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>
ecc5e78 to
32b6e84
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added check for '../' in URL validation to prevent SSRF.
TheWitness
approved these changes
Mar 29, 2026
bmfmancini
approved these changes
Mar 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
lib/database.php:2228
- In db_dump_data(), $credentials_string is still built by concatenating raw credential values (e.g. --host, --ssl-ca paths) directly into the shell command. Even with $database/$username/$password/$output_file escaped, this leaves room for shell metacharacters or spaces in those values to break the command (and can reintroduce command injection if any caller passes untrusted credentials). Build $credentials_string using cacti_escapeshellarg() for values (and ensure flags/keys are validated) before interpolating into exec().
if (cacti_sizeof($credentials)) {
foreach ($credentials as $key => $value) {
$name = trim($key);
if (strstr($name, '--') !== false) { //name like --host
if($name == '--password') {
$password = $value;
} elseif ($name == '--user') {
$username = $value;
} else {
$credentials_string .= $name . '=' . $value . ' ';
}
} elseif(strstr($name, '-') !== false) { //name like -h
if($name == '-p') {
$password = $value;
} elseif ($name == '-u') {
$username = $value;
} else {
$credentials_string .= $name . $value . ' ';
}
} else { //name like host
if($name == 'password') {
$password = $value;
} elseif ($name == 'user') {
$username = $value;
} else {
$credentials_string .= '--' . $name . '=' . $value . ' ';
}
bmfmancini
approved these changes
Mar 29, 2026
xmacan
approved these changes
Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Surgical defense-in-depth fixes. +14/-5 lines, 3 files.
call_remote_data_collector()rejects://and@to prevent SSRF$database,$username,$password,$output_fileindb_dump_data()exec calls viacacti_escapeshellarg()$titleinhtml_start_box()viahtml_escape()to prevent stored XSSAll three have limited exploitability (admin-only callers, DB-sourced inputs, translated string titles) but are worth hardening per security audit findings.
Test plan
cli/audit_database.phpdump still works