Repository navigation
Security hardening: check.php auth, output escaping, output-file confinement, group visibility, format-string guard #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cf23426
fix: Escape map titles and info URLs before output
somethingwithproof fb892b3
fix: Require Cacti authentication for the web check page
somethingwithproof 9dad0b4
fix: Accept a non-string map title without a TypeError
somethingwithproof a760f9d
fix: Escape map titles reflected back into messages and the feed
somethingwithproof c400976
fix: Keep a percent sign in a map title from breaking the RSS feed
somethingwithproof 6ef63de
fix: Enforce the Manage Weathermap realm in check.php itself
somethingwithproof aba7ecb
test: Strengthen the check.php access-guard tests
somethingwithproof 1d9cf4b
test: Drive the check.php guard with PHP's built-in server
somethingwithproof 4c1cf8c
fix: Confine map output-file directives to the plugin output directory
somethingwithproof 0dc08c6
fix: Hide maps from members of a disabled user group
somethingwithproof e71c28b
fix: Treat an invalid map format string as literal text
somethingwithproof 15f1469
docs: Note the security hardening changes in the changelog
somethingwithproof 77a1010
chore(i18n): regenerate cacti.pot for the escaped title strings
somethingwithproof d1a589e
fix(security): refuse linked output files and accept ordinary output …
somethingwithproof c1e681a
test: load map_clean_title() where the fixtures extract map_duplicate()
somethingwithproof 4ec76f2
refactor: move map_clean_title() into lib/map-title.php
somethingwithproof d3f832f
test: run the poller over maps with confined and refused output files
somethingwithproof 6624e72
test: list the refused output paths as one dataset
somethingwithproof 2b23134
Merge remote-tracking branch 'origin/develop' into wt-wm-348-merge
fea6c18
chore: release version 2.1 and promote the develop changelog section
da88eb0
security: reject executable-scheme info URLs and per-directive output…
ae597a3
security: decode HTML entities before the info-URL scheme check
863cd0f
security: cap duplicated-map title length to block config-directive i…
8402e62
security: account for preserved TITLE indentation in the duplicate-ti…
c027e5a
security: check every substituted line, not just TITLE, for the chunk…
cf5a55e
test: cover wm_href_is_safe guard branches for the patch-coverage gate
0ec25d7
refactor: extract duplicate-title line guard into a testable helper
199e579
test: fold the per-directive extension cases into one dataset
2ba1e8c
test: de-duplicate the image-map href cases for the SonarCloud gate
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group, Howard Jones | | ||
| | | | ||
| | This program is free software; you can redistribute it and/or | | ||
| | modify it under the terms of the GNU General Public License | | ||
| | as published by the Free Software Foundation; either version 2 | | ||
| | of the License, or (at your option) any later version. | | ||
| | | | ||
| | This program is distributed in the hope that it will be useful, | | ||
| | but WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | ||
| | GNU General Public License for more details. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| /** | ||
| * Flattens a map title so it cannot inject map-config directives. | ||
| * | ||
| * Map configs are line oriented, and a duplicated map has its title substituted | ||
| * into the copied config file's TITLE line. A title carrying a newline would | ||
| * otherwise append arbitrary directives (such as NODE or INFOURL) to that | ||
| * config, so every control character is collapsed to a space and the result is | ||
| * trimmed. A non-string value (for example an array from a `title[]=` request | ||
| * variable) yields an empty string rather than a TypeError. | ||
| * | ||
| * @param mixed $title The raw title, from a request variable or the stored map. | ||
| * @return string The single-line title, safe to write into a config file. | ||
| */ | ||
| function map_clean_title($title): string { | ||
| /* The title arrives from a request variable by way of str_replace(), so an | ||
| * array valued parameter such as title[]= would otherwise reach the string | ||
| * type declaration here and raise a TypeError. */ | ||
| if (!is_string($title)) { | ||
| return ''; | ||
| } | ||
|
|
||
| return trim(preg_replace('/[\x00-\x1f\x7f]+/', ' ', $title) ?? $title); | ||
| } | ||
|
|
||
| /** | ||
| * Reports whether substituting a duplicated title would overflow a config line. | ||
| * | ||
| * map_duplicate() copies a map by replacing "TITLE <old>" with "TITLE <new>" | ||
| * across the source config with a whole-file str_replace(), which also rewrites | ||
| * the string wherever else it appears (an indented TITLE line, or a comment or | ||
| * label that happens to contain it). ReadConfig() parses the config with | ||
| * fgets($fd, 4096) and trims each chunk, so a rewritten line that reaches that | ||
| * boundary is split and its trimmed tail is parsed as a separate directive, | ||
| * even past a leading '#'. A line is read whole only when its bytes plus the | ||
| * newline fit in one 4096-byte read, i.e. the line is at most 4094 bytes, so | ||
| * reject the substitution when any line it lengthens would exceed that. | ||
| * | ||
| * @param mixed $old_title The source map's cached title (the TITLE value). | ||
| * @param mixed $new_title The cleaned title the duplicate will carry. | ||
| * @param mixed $contents The source config file's contents. | ||
| * @return bool True when the substitution would overflow a config line. | ||
| */ | ||
| function map_duplicate_title_overflows_line($old_title, $new_title, $contents): bool { | ||
| if (!is_string($contents) || !is_string($old_title) || !is_string($new_title)) { | ||
| return false; | ||
| } | ||
|
|
||
| $marker = 'TITLE ' . $old_title; | ||
|
|
||
| foreach (explode("\n", $contents) as $line) { | ||
| if (strpos($line, $marker) !== false | ||
| && strlen(str_replace($marker, 'TITLE ' . $new_title, $line)) > 4094) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.