Skip to content

fix: use prepared statements for device-reported values and require POST for admin actions - #401

Merged
TheWitness merged 2 commits into
Cacti:developfrom
somethingwithproof:fix/scanner-sql-and-admin-post
Oct 23, 2026
Merged

TheWitness merged 2 commits into
Cacti:developfrom
somethingwithproof:fix/scanner-sql-and-admin-post

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Description

This PR changes two things. First, the interface and interface-graph inserts in lib/mactrack_functions.php now use prepared statements, as do the ARP, DHCP snooping and 802.1x inserts in the Cisco, Aruba AOS-CX, Enterasys N7, H3C/3Com and Extreme scanners. The rows, columns and duplicate-key handling are unchanged. A missing sysUptime is bound as '', as the old SQL inserted it, rather than NULL. Second, rescan, site scan, enable and disable now refuse anything other than POST with a 405. js/mactrack.js sends them as POST with __csrf_magic and shows Cacti's error dialog if the request fails.

Motivation and Context

Device-reported values should reach the database as bound parameters. The four admin actions change state, and Cacti checks the CSRF token on POST requests only.

How Has This Been Tested?

  • Pest on PHP 8.4.25 and 8.2.31: 246 passed, which is the 226 existing tests plus 20 new ones. Patch coverage is 100%, and php -l on PHP 7.4 is clean.
  • I ran each changed scanner path against MariaDB 10.11 through Cacti's lib/database.php, before and after the change. I did this on PHP 7.4 and 8.3 with Cacti 1.2.14, 1.2.25 and 1.2.31, with and without a NULL sysUptime. The table contents were identical in every run.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

This touches the same two statements as #400, so whichever merges second needs a rebase.

The interface, interface-graph, ARP, DHCP snooping and 802.1x scanners now
bind the strings a device reports instead of building them into the SQL.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Rescan, site scan, enable and disable now refuse any other method with a
405, and js/mactrack.js posts them with the CSRF token and reports failures.

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

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
7.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@TheWitness
TheWitness merged commit f0817de into Cacti:develop Oct 23, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants