Skip to content

Multiple Fixes: Range Pruning, Callback Execution, Early Rotation, CSV Export Hardening, Prepared Statements, SQL Readability#313

Merged
TheWitness merged 11 commits intodevelopfrom
partition-export
Apr 10, 2026
Merged

Multiple Fixes: Range Pruning, Callback Execution, Early Rotation, CSV Export Hardening, Prepared Statements, SQL Readability#313
TheWitness merged 11 commits intodevelopfrom
partition-export

Conversation

@TheWitness
Copy link
Copy Markdown
Member

  • Fix partitioning so that it happens an hour before the rotation
  • Fix CSV Export to be secure using built-in function
  • Fix Use logtime as a timestamp to improve range partition pruning
  • Fix properly execute the program callback when the value changes on the syslog page

Closes #199 #260 #256

* Fix partitioning so that it happens an hour before the rotation
* Fix CSV Export to be secure using built-in function
Also missed a few prepared statements.
* Properly execute the syslog callback without using eval
* Use a timestamp to improve the quality of range partition pruning
* Better formatting on UNION queries
@TheWitness TheWitness changed the title Partition export Multiple Fixes: Range Pruning, Callback Execution, Early Rotation, CSV Export Hardening, Prepared Statements, SQL Readability Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 targets the Cacti Syslog plugin’s data lifecycle and UI hardening: improving partition rotation behavior (incl. DST edge cases), securing CSV exports, and hardening client-side callback execution.

Changes:

  • Adjusts partition creation timing/logic and updates schema partitioning to use UNIX_TIMESTAMP(logtime) (with UTC-based date calculations).
  • Reworks CSV export to use fputcsv() for proper CSV escaping.
  • Removes eval()-based autocomplete callbacks and adds a string-based function dispatcher; adds additional HTML escaping in UI outputs.

Reviewed changes

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

Show a summary per file
File Description
setup.php Changes partitioned syslog table definition to partition by UNIX_TIMESTAMP(logtime) and tweaks table DDL quoting.
functions.php Updates partition management timing/signatures; switches export output to fputcsv(); converts many SQL strings to interpolated backtick form and more prepared statements.
syslog.php Updates various SQL strings to interpolated backtick form and adds HTML escaping in select options; refactors some query formatting.
syslog_reports.php Moves report enable/disable/remove operations to prepared statements; SQL quoting adjustments.
syslog_removal.php SQL quoting adjustments for removal rule queries.
syslog_alerts.php Fixes alert enable query to use syslog_db_execute_prepared; SQL quoting adjustments.
js/functions.js Replaces eval() with a function-by-name executor; attempts to sanitize host dropdown option rendering.

xmacan
xmacan previously approved these changes Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

xmacan
xmacan previously approved these changes Apr 10, 2026
@TheWitness TheWitness merged commit bb45b9b into develop Apr 10, 2026
8 checks passed
@TheWitness TheWitness deleted the partition-export branch April 10, 2026 17:37
somethingwithproof added a commit to somethingwithproof/plugin_syslog that referenced this pull request Apr 10, 2026
Follow-up to Cacti#313. Addresses eight correctness and hardening findings:

- Partition boundary math is now computed as integer epochs in PHP
  (next UTC midnight) and injected as numeric literals. strtotime()
  and UNIX_TIMESTAMP('date-literal') both pulled the PHP/MySQL
  session TZ into UTC-intended math and caused drift at day
  boundaries on non-UTC servers.

- syslog_partition_create() now hard-fails with an error log instead
  of silently warning when SHOW CREATE TABLE does not expose either
  TO_DAYS or UNIX_TIMESTAMP. Silent no-ops caused rotations to stall
  unnoticed. Rewrote str_contains() to strpos() for portability.

- syslog_manage_items() validates $from_table/$to_table against a
  three-value allowlist before interpolation. Defense-in-depth for
  the one caller that currently passes safe literals.

- Alert, removal, and report rule handlers of type sql are gated on
  a new 'syslog_allow_sql_rules' setting (off by default). These
  handlers inline admin-defined SQL into the WHERE clause and
  cannot be parameterised; the previous removal handler also
  emitted invalid syntax ("WHERE message (expr)"). Added a Security
  Settings section to setup.php with a warning description.

- CSV export replaces lossy trim($x, ' =+-@') with a syslog_csv_safe()
  helper that prepends a single quote only when the first character
  is one of =+-@, TAB, CR. Preserves content verbatim while defusing
  spreadsheet formula injection per OWASP guidance.

- Host autocomplete dropdown builds <option> elements via jQuery's
  attr()/text() instead of HTML string concatenation wrapped in
  DOMPurify.sanitize(). DOMPurify does not escape attribute
  delimiters, so a host containing a double quote could still break
  out of the class/value attribute.

- Autocomplete onChange dispatcher enforces a bare-identifier
  whitelist and looks the callback up as a direct window[name]
  property. Rejects dotted paths, arguments, and anything that is
  not a function, with a console.warn. Server side, the three
  initSyslogAutocomplete arguments now go through json_encode()
  instead of single-quote interpolation.

- Ported tests/regression/issue254_partition_table_locking_test.php
  to the new syslog_partition_check/create two-argument signatures
  and extended it to assert the UTC-midnight boundary arithmetic,
  the hard-fail on unknown partition expression, and the
  syslog_manage_items table-name allowlist.

Verification:
- php -l on every touched file
- node -c on js/functions.js
- all eight regression tests in tests/regression/ that pass on
  develop continue to pass; issue254 was restored and passes;
  three pre-existing failures (issue253, issue269 x2) are
  unchanged on develop.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof added a commit to somethingwithproof/plugin_syslog that referenced this pull request Apr 10, 2026
Addresses code review feedback on the PR Cacti#313 follow-up. The boundary
epoch calculation ((int)($time / 86400) + 1) * 86400 assumes a
non-negative UTC timestamp; non-numeric or pre-epoch values would
silently underflow. Reject them at function entry with a logged error
and a false return, matching the other guard clauses in the function.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
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.

[4.0] - Duplicate Partition name errors

4 participants