-
Notifications
You must be signed in to change notification settings - Fork 8
hardening: prepared statements, PHP 7.4 idioms, and security fixes #49
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
5
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
5 commits
Select commit
Hold shift + click to select a range
a8cca1d
refactor(php74): use null coalescing (??) and ??= operators
somethingwithproof 6cd5c54
test: expand security test coverage for hardening changes
somethingwithproof 8557bff
style: align plugin with Cacti PHP coding standard
somethingwithproof 0aafc75
ci: remove unavailable versioned Apache PHP package
somethingwithproof c9b5610
fix: unescaped quotes in security test regexes break php -l
somethingwithproof 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "name": "cacti/plugin_maint", | ||
| "description": "plugin_maint plugin for Cacti", | ||
| "license": "GPL-2.0-or-later", | ||
| "require-dev": { | ||
| "pestphp/pest": "^1.23" | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "pestphp/pest-plugin": true | ||
| } | ||
| }, | ||
| "autoload-dev": { | ||
| "files": [ | ||
| "tests/bootstrap.php" | ||
| ] | ||
| } | ||
| } |
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,10 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| require_once __DIR__ . '/bootstrap.php'; |
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,66 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| describe('auth guard presence in maint', function () { | ||
| it('includes auth.php or global.php in all UI entry points', function () { | ||
| $uiFiles = array( | ||
| 'functions.php', | ||
| 'maint.php', | ||
| ); | ||
|
|
||
| foreach ($uiFiles as $relativeFile) { | ||
| $path = realpath(__DIR__ . '/../../' . $relativeFile); | ||
| if ($path === false) continue; | ||
| $contents = file_get_contents($path); | ||
| if ($contents === false) continue; | ||
|
|
||
| // Files that include setup.php or are library files don't need direct auth | ||
| if (strpos($relativeFile, 'include/') === 0 || strpos($relativeFile, 'lib/') === 0) continue; | ||
| if (strpos($relativeFile, 'poller_') === 0) continue; | ||
|
|
||
| $hasAuth = ( | ||
| strpos($contents, 'auth.php') !== false || | ||
| strpos($contents, 'global.php') !== false || | ||
| strpos($contents, 'global_arrays.php') !== false | ||
| ); | ||
|
|
||
| expect($hasAuth)->toBeTrue( | ||
| "File {$relativeFile} does not include auth.php or global.php" | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('validates numeric IDs from request variables before DB queries', function () { | ||
| $uiFiles = array( | ||
| 'functions.php', | ||
| 'maint.php', | ||
| ); | ||
|
|
||
| foreach ($uiFiles as $relativeFile) { | ||
| $path = realpath(__DIR__ . '/../../' . $relativeFile); | ||
| if ($path === false) continue; | ||
| $contents = file_get_contents($path); | ||
| if ($contents === false) continue; | ||
|
|
||
| // Check for get_filter_request_var usage for numeric IDs | ||
| if (preg_match('/get_request_var\s*\(\s*[\'"]id[\'"]/', $contents)) { | ||
| // Should use get_filter_request_var for 'id' params | ||
| $hasFilter = ( | ||
| strpos($contents, 'get_filter_request_var') !== false || | ||
| strpos($contents, 'input_validate_input_number') !== false || | ||
| strpos($contents, 'form_input_validate') !== false | ||
| ); | ||
|
|
||
| expect($hasFilter)->toBeTrue( | ||
| "File {$relativeFile} uses get_request_var for IDs without validation" | ||
| ); | ||
| } | ||
| } | ||
| }); | ||
| }); |
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,86 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| describe('output escaping in maint', function () { | ||
| it('does not interpolate raw variables into HTML attributes', function () { | ||
| $uiFiles = [ | ||
| 'functions.php', | ||
| 'maint.php', | ||
| ]; | ||
|
|
||
| foreach ($uiFiles as $relativeFile) { | ||
| $path = realpath(__DIR__ . '/../../' . $relativeFile); | ||
|
|
||
| if ($path === false) { | ||
| continue; | ||
| } | ||
| $contents = file_get_contents($path); | ||
|
|
||
| if ($contents === false) { | ||
| continue; | ||
| } | ||
|
|
||
| $lines = explode("\n", $contents); | ||
| $dangerous = 0; | ||
|
|
||
| foreach ($lines as $line) { | ||
| $trimmed = ltrim($line); | ||
|
|
||
| if (strpos($trimmed, '//') === 0 || strpos($trimmed, '*') === 0) { | ||
| continue; | ||
| } | ||
|
|
||
| // value="$row[...] without html_escape wrapping | ||
| if (preg_match('/value\s*=\s*["\'"]\s*<\?php\s+echo\s+\$/', $line)) { | ||
| $dangerous++; | ||
| } | ||
|
|
||
| // title="<?php print $something without escaping | ||
| if (preg_match('/(?:title|alt|placeholder)\s*=.*print\s+\$(?!_|config)/', $line)) { | ||
| if (strpos($line, 'html_escape') === false && strpos($line, '__esc') === false && strpos($line, 'htmlspecialchars') === false) { | ||
| $dangerous++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| expect($dangerous)->toBe(0, | ||
| "File {$relativeFile} has unescaped variables in HTML attributes" | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('uses html_escape or __esc for user-controlled output', function () { | ||
| $uiFiles = [ | ||
| 'functions.php', | ||
| 'maint.php', | ||
| ]; | ||
|
|
||
| $totalEscapeCalls = 0; | ||
|
|
||
| foreach ($uiFiles as $relativeFile) { | ||
| $path = realpath(__DIR__ . '/../../' . $relativeFile); | ||
|
|
||
| if ($path === false) { | ||
| continue; | ||
| } | ||
| $contents = file_get_contents($path); | ||
|
|
||
| if ($contents === false) { | ||
| continue; | ||
| } | ||
|
|
||
| $totalEscapeCalls += preg_match_all('/html_escape|__esc\(|htmlspecialchars/', $contents); | ||
| } | ||
|
|
||
| // At least some escaping should be present in UI files | ||
| expect($totalEscapeCalls)->toBeGreaterThan(0, | ||
| 'UI files should contain at least one html_escape/__esc call' | ||
| ); | ||
| }); | ||
| }); |
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.