Repository navigation
security: move inline event handlers to CSP-safe bindings #287
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
4 commits
Select commit
Hold shift + click to select a range
ca76a66
security: move inline event handlers to CSP-safe bindings
b1e0bf4
Add functions.php inclusion to FlowviewFilterControlsTest
TheWitness 4c08bc7
Update FlowviewFilterControlsTest expectations
TheWitness ccb9521
test: stub array_rekey so FlowviewFilterControls render reaches time-…
TheWitness 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
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,63 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| /* | ||
| * Unit coverage for the filter controls rendered by flowview_display_filter() | ||
| * in includes/functions.php. The time-shift icons use CSP-safe | ||
| * timeshiftBackward / timeshiftForward classes (bound via a delegated handler) | ||
| * rather than inline onclick attributes. | ||
| */ | ||
|
|
||
| beforeAll(function () { | ||
| require_once __DIR__ . '/../../setup.php'; | ||
| require_once __DIR__ . '/../../includes/functions.php'; | ||
|
|
||
| // The full filter render calls a handful of Cacti UI helpers the unit | ||
| // harness does not otherwise need; stub the ones it does not already define. | ||
| if (!function_exists('html_start_box')) { function html_start_box(...$args) {} } | ||
| if (!function_exists('html_end_box')) { function html_end_box(...$args) {} } | ||
| if (!function_exists('title_trim')) { function title_trim($text, $length = 0) { return (string) $text; } } | ||
| if (!function_exists('html_escape_request_var')) { function html_escape_request_var($name) { return ''; } } | ||
|
|
||
| // includes/arrays.php (required inside flowview_display_filter) re-keys its | ||
| // device/template lookups with Cacti core's array_rekey(), which the stub | ||
| // harness does not provide; mirror core's behaviour so the require succeeds. | ||
| if (!function_exists('array_rekey')) { | ||
| function array_rekey($array, $key, $value) { | ||
| $ret = array(); | ||
| if (is_array($array)) { | ||
| foreach ($array as $item) { | ||
| $k = $item[$key]; | ||
| if (is_array($value)) { | ||
| foreach ($value as $v) { $ret[$k][$v] = $item[$v]; } | ||
| } else { | ||
| $ret[$k] = $item[$value]; | ||
| } | ||
| } | ||
| } | ||
| return $ret; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('renders the time-shift controls with CSP-safe classes and no inline handlers', function () { | ||
| ob_start(); | ||
|
|
||
| try { | ||
| flowview_display_filter(); | ||
| } catch (\Throwable $e) { | ||
| // The complete filter form references optional helpers that are not part | ||
| // of the isolated unit harness; the CSP-relevant controls are emitted | ||
| // before any such reference, so the captured output still covers them. | ||
| } | ||
|
|
||
| $output = ob_get_clean(); | ||
|
|
||
| expect($output)->toContain('timeshiftBackward'); | ||
| expect($output)->toContain('timeshiftForward'); | ||
| expect($output)->not->toMatch('/\son(?:click|change)\s*=/i'); | ||
| }); |
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.