-
Notifications
You must be signed in to change notification settings - Fork 4
hardening: prepared statements, PHP 7.4 idioms, and security fixes #51
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
Open
somethingwithproof
wants to merge
3
commits into
Cacti:develop
Choose a base branch
from
somethingwithproof:hardening/comprehensive
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | Shared helpers for audit request normalization and output escaping. | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| if (!function_exists('audit_normalize_int')) { | ||
| function audit_normalize_int($value, $default = -1) { | ||
| if (is_int($value)) { | ||
| return $value; | ||
| } | ||
|
|
||
| if (is_string($value) && preg_match('/^-?[0-9]+$/', $value)) { | ||
| return (int)$value; | ||
| } | ||
|
|
||
| return (int)$default; | ||
| } | ||
| } | ||
|
|
||
| if (!function_exists('audit_html_escape')) { | ||
| function audit_html_escape($value) { | ||
| $value = (string)$value; | ||
|
|
||
| if (function_exists('html_escape')) { | ||
| return html_escape($value); | ||
| } | ||
|
|
||
| return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); | ||
| } | ||
| } |
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,45 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | Integration checks for audit detail escaping helpers. | | ||
| | | | ||
| | Run: php tests/integration/test_detail_render_escaping.php | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| $pass = 0; | ||
| $fail = 0; | ||
|
|
||
| function assert_true($label, $value) { | ||
| global $pass, $fail; | ||
|
|
||
| if ($value) { | ||
| echo "PASS $label\n"; | ||
| $pass++; | ||
| } else { | ||
| echo "FAIL $label\n"; | ||
| $fail++; | ||
| } | ||
| } | ||
|
|
||
| require_once __DIR__ . '/../../audit_helpers.php'; | ||
|
|
||
| $rendered_field = audit_html_escape('"><img src=x onerror=alert(1)>'); | ||
| $rendered_json = audit_html_escape(json_encode(array('payload' => '<svg onload=alert(1)>'))); | ||
|
|
||
| assert_true( | ||
| 'field names are escaped before rendering', | ||
| strpos($rendered_field, '<img') === false && strpos($rendered_field, '<img') !== false | ||
| ); | ||
|
|
||
| assert_true( | ||
| 'record data json is escaped before rendering', | ||
| strpos($rendered_json, '<svg') === false && strpos($rendered_json, '<svg') !== false | ||
| ); | ||
|
|
||
| echo "\n"; | ||
| echo "Results: $pass passed, $fail failed\n"; | ||
|
|
||
| exit($fail > 0 ? 1 : 0); |
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,47 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | Unit checks for audit security helpers. | | ||
| | | | ||
| | Run: php tests/unit/test_security_helpers.php | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| $pass = 0; | ||
| $fail = 0; | ||
|
|
||
| function assert_true($label, $value) { | ||
| global $pass, $fail; | ||
|
|
||
| if ($value) { | ||
| echo "PASS $label\n"; | ||
| $pass++; | ||
| } else { | ||
| echo "FAIL $label\n"; | ||
| $fail++; | ||
| } | ||
| } | ||
|
|
||
| require_once __DIR__ . '/../../audit_helpers.php'; | ||
|
|
||
| assert_true( | ||
| 'integer normalization keeps valid integers', | ||
| audit_normalize_int('42', -1) === 42 | ||
| ); | ||
|
|
||
| assert_true( | ||
| 'integer normalization rejects mixed payloads', | ||
| audit_normalize_int('0 OR 1=1', -1) === -1 | ||
| ); | ||
|
|
||
| assert_true( | ||
| 'html escaping encodes script payloads', | ||
| audit_html_escape('<script>alert(1)</script>') === '<script>alert(1)</script>' | ||
| ); | ||
|
|
||
| echo "\n"; | ||
| echo "Results: $pass passed, $fail failed\n"; | ||
|
|
||
| exit($fail > 0 ? 1 : 0); |
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,48 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | End-to-end wiring checks for audit security fixes. | | ||
| | | | ||
| | Run: php tests/e2e/test_security_wiring.php | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| $pass = 0; | ||
| $fail = 0; | ||
|
|
||
| function assert_true($label, $value) { | ||
| global $pass, $fail; | ||
|
|
||
| if ($value) { | ||
| echo "PASS $label\n"; | ||
| $pass++; | ||
| } else { | ||
| echo "FAIL $label\n"; | ||
| $fail++; | ||
| } | ||
| } | ||
|
|
||
| $source = file_get_contents(__DIR__ . '/../../audit.php'); | ||
|
|
||
| assert_true( | ||
| 'user_id filter uses integer normalization before SQL concatenation', | ||
| substr_count($source, "audit_normalize_int(get_request_var('user_id'), -1)") === 2 | ||
| ); | ||
|
|
||
| assert_true( | ||
| 'detail popup escapes field names and values', | ||
| strpos($source, "audit_html_escape(\$field)") !== false && | ||
| strpos($source, "audit_html_escape(\$content)") !== false | ||
| ); | ||
|
|
||
| assert_true( | ||
| 'record data json is escaped before rendering', | ||
| strpos($source, "audit_html_escape(json_encode(\$record, JSON_PRETTY_PRINT))") !== false | ||
| ); | ||
|
|
||
| echo "\n"; | ||
| echo "Results: $pass passed, $fail failed\n"; | ||
|
|
||
| exit($fail > 0 ? 1 : 0); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description states the changes have "zero behavioral impact", but escaping values with html_escape() changes the rendered output (e.g., special characters will display escaped) and is a functional/security behavior change. Please update the PR description (or note this as an intentional behavior change) so reviewers/operators aren't surprised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct observation. The ?? operator preserves behavior when the value is set. The only behavioral difference is when the value is null, which previously would have triggered an undefined variable notice.