Skip to content

fix: use core SQL, shell and escaping APIs in the Databases, Filters and CLI scripts - #322

Open
somethingwithproof wants to merge 7 commits into
developfrom
fix/idiomatic-core-api
Open

somethingwithproof wants to merge 7 commits into
developfrom
fix/idiomatic-core-api

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Fixes #321

Intent: replace hand-built SQL, shell commands and HTML output with the Cacti core API in files that #297 does not touch.

Scope: flowview_databases.php (details lookup accepts only table columns; registry, DNS cache and Source values escaped), flowview_filters.php (Filter and listener names escaped; actions use prepared statements), flowview_process.php (bound schedule query), flowview_bulkarin.php (escaped whois arguments), flowview_upgrade.php (set_config_option()). New tests and two CI steps. Findings in #297's files are listed in the issue, deferred. No CHANGELOG entry, as #297 edits CHANGELOG.md.

Risk: low. Valid requests behave as before; a details request whose keys are not columns of the table now returns no row.

Verification (local, PHP 8.5, MariaDB 11.8, Cacti 1.2.x): existing suite 410 passed; new unit test 4 passed; new end-to-end tests 10 passed (logged-in HTTP through php -S, a user without the realm, and the bulk ARIN loader and poller run as subprocesses). Reverting each escaping, allow-list and shell fix makes at least one test fail. Hosted CI not yet run.

The registry details lookup on the Databases page built its WHERE
clause from the keys of the row id sent by the browser. Column names
can not be bound, so only columns of the table are now accepted and
any other key returns no row.

The Disable, Enable and Delete actions of the Filters page and the
poller's query for due schedules now bind their values instead of
concatenating them.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The Databases page printed registry, DNS cache and ARIN values, and the
source options of its filters, without escaping. The Filters page did
the same with the listener name in the list and the Filter names in the
action confirmation. Escape them with html_escape().

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
flowview_bulkarin.php passed the whois path, provider and CIDR to the
shell unescaped. Escape them with cacti_escapeshellcmd() and
cacti_escapeshellarg(), as core does for external commands.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The upgrade script wrote plugin_flowview_version straight into the
settings table. set_config_option() performs the same REPLACE and keeps
Cacti's settings handling in one place.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
A unit test runs flowview_get_item_details() against the unit doubles
and checks that only table columns reach the query. End-to-end tests
log in to a served Cacti and check the details lookup, its realm
check, the escaped Databases and Filters output and Filter deletion,
and run the bulk ARIN loader and the poller as subprocesses.

The end-to-end tests skip unless FLOWVIEW_E2E_* is set.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Serve the installed Cacti with PHP's built-in server and run
tests/Integration after the unit tests, with the database and host
settings in FLOWVIEW_E2E_*.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the core request, SQL, shell and escaping APIs in the Databases, Filters and CLI scripts

2 participants