Skip to content

hardening: prepared statements, path containment, and output escaping - #153

Open
somethingwithproof wants to merge 10 commits into
Cacti:developfrom
somethingwithproof:fix/hardening-150
Open

hardening: prepared statements, path containment, and output escaping#153
somethingwithproof wants to merge 10 commits into
Cacti:developfrom
somethingwithproof:fix/hardening-150

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Apr 9, 2026

Copy link
Copy Markdown
Member

Security fixes for the Router Configs UI. Scoped to plugin code; the Pest scaffold that was in this branch has been dropped, and the vendored Horde exception class is left untouched.

  • Prepared statements and intval on the device IN-list, replacing interpolated ids.
  • Backup file reads are anchored: basename() on the filename, then realpath() compared against the base directory plus a separator. A bare prefix test also accepts a sibling such as backups-evil.
  • html_escape on device hostname, address, directory, filename, and the rendered config body.
  • unserialize() with allowed_classes => false plus a structure check on the decoded credential, and the debug log that printed its shape is gone.

The apt line drops libapache2-mod-php, which conflicts with the version setup-php installs.

Note for release planning: these are post-authentication issues, reachable by any account holding the Router Configs realm, but SQL injection and arbitrary file read are not low impact. The diff is already public, so the useful move is to land and ship rather than close.

Copilot AI review requested due to automatic review settings April 9, 2026 06:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the RouterConfigs Cacti plugin by reducing injection/XSS risk and tightening a few correctness issues across UI pages, upgrade logic, and credential handling.

Changes:

  • Convert several SQL calls to prepared statements and cast numeric parameters where applicable.
  • Escape user-/device-sourced output in UI views (device debug/config, accounts, device types, compare selectors).
  • Add stricter file-path handling for backup reads and safer credential decoding (unserialize with allowed_classes=false), plus small typo/HTML tag fixes.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Text/Exception/Pear.php Replace legacy isset() ternaries with ?? and fix “unkown” typo.
setup.php Parameterize realm migration and plugin version update queries; use ??= for poller interval default.
router-download.php Use ??= / ?? for cleaner defaults in CLI option parsing.
router-devtypes.php Escape rendered fields; parameterize paging query; safer ID handling in action list rendering.
router-devices.php Fix mismatched heading tag; escape debug output and parameterize device lookup in edit path.
router-compare.php Escape option labels, normalize option values, add file path validation and fix wrong backup-id message.
include/functions.php Harden IN-clause ID handling; safer credential decode; add file-path validation + escape config output.

Comment thread setup.php Outdated
Comment thread router-compare.php Outdated
Comment thread include/functions.php Outdated
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Add targeted tests for prepared statement migration, output escaping,
auth guard presence, CSRF token validation, redirect safety, and
PHP 7.4 compatibility. Tests use source-scan patterns that verify
security invariants without requiring the Cacti database.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
netniV
netniV previously approved these changes Aug 16, 2026
@netniV

netniV commented Aug 16, 2026

Copy link
Copy Markdown
Member

@somethingwithproof There are a bunch of conflicts on this PR.

@somethingwithproof somethingwithproof changed the title hardening: prepared statements, PHP 7.4 idioms, and bug fixes hardening: prepared statements, path containment, and output escaping Aug 20, 2026
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
# Conflicts:
#	include/functions.php
#	router-accounts.php
#	router-devtypes.php
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.

3 participants