security: escape output in threshold web views - #818
Open
somethingwithproof wants to merge 1 commit into
Open
Conversation
Escapes page, id and drp_action where they print into hidden inputs, wraps AJAX filter parameters in encodeURIComponent(). Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the thold plugin’s web-facing threshold views by reducing XSS risk in rendered HTML/JS, and by improving safety of user-supplied filter values used in SQL RLIKE clauses.
Changes:
- Escapes request-derived values before rendering into hidden form inputs.
- Wraps AJAX filter parameters with
encodeURIComponent()when building URLs client-side. - Quotes
rfiltervalues viadb_qstr()for RLIKE SQL fragments, and adds a safer unserialize fallback path forselected_graphs_array.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| thold.php | Quotes RLIKE filter operand and escapes page when rendered into a hidden input; URL-encodes filter parameters in JS. |
| thold_graph.php | Applies the same URL-encoding and output escaping patterns; quotes multiple RLIKE filter operands. |
| thold_webapi.php | URL-encodes wizard filter parameters; adds guarded unserialize/sanitization logic for nested graph selection payloads. |
| thold_templates.php | URL-encodes the filter value when applying the templates page filter via JS. |
Suppressed comments (2)
thold_graph.php:942
- These host filter RLIKE clauses are now quoted via db_qstr(), which addresses SQL injection but doesn’t apply Cacti’s RLIKE-specific hardening (db_qstr_rlike). Consider using db_qstr_rlike() when available (fallback to db_qstr) so the operand is bounded/cleaned per core mitigation.
if (get_request_var('rfilter') != '') {
$sql_where .= " (h.deleted = ''
AND (h.hostname " . 'RLIKE ' . db_qstr(get_request_var('rfilter')) . '
OR h.description ' . 'RLIKE ' . db_qstr(get_request_var('rfilter')) . ')';
}
thold_graph.php:1494
- This RLIKE clause is quoted with db_qstr(), but doesn’t use Cacti’s RLIKE-specific hardening helper (db_qstr_rlike). Consider using db_qstr_rlike() when available (fallback to db_qstr) so the regex operand is bounded/cleaned consistently with core mitigations.
if (get_request_var('rfilter') != '') {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' tl.description ' . 'RLIKE ' . db_qstr(get_request_var('rfilter'));
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
616
to
618
| if (get_request_var('rfilter') != '') { | ||
| $sql_where .= ($sql_where == '' ? '(' : ' AND ') . " td.name_cache RLIKE '" . get_request_var('rfilter') . "'"; | ||
| $sql_where .= ($sql_where == '' ? '(' : ' AND ') . ' td.name_cache ' . 'RLIKE ' . db_qstr(get_request_var('rfilter')); | ||
| } |
Comment on lines
406
to
408
| if (get_request_var('rfilter') != '') { | ||
| $sql_where .= ($sql_where == '' ? '(' : ' AND ') . " td.name_cache RLIKE '" . get_request_var('rfilter') . "'"; | ||
| $sql_where .= ($sql_where == '' ? '(' : ' AND ') . 'td.name_cache ' . 'RLIKE ' . db_qstr(get_request_var('rfilter')); | ||
| } |
Comment on lines
1397
to
1399
| if (get_request_var('rfilter') != '') { | ||
| $sql_where .= ($sql_where == '' ? '' : ' AND') . " tl.description RLIKE '" . get_request_var('rfilter') . "'"; | ||
| $sql_where .= ($sql_where == '' ? '' : ' AND') . ' tl.description ' . 'RLIKE ' . db_qstr(get_request_var('rfilter')); | ||
| } |
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.
Escapes output that reaches the browser from threshold web views:
page,idand
drp_actionwhere they print into hidden inputs, and AJAX filter parameterswrapped in
encodeURIComponent().The
rfiltervalue is quoted throughdb_qstr()where it builds RLIKE clauses,replacing raw interpolation.
Split out of #773 as one concern. No behaviour change beyond escaping.