Skip to content

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

In review

Description

@somethingwithproof

Several FlowView files outside the NBAR work still build SQL, shell commands and HTML by hand where Cacti's core API does the job. Each of these was read for realm and reachability, and the changes below keep behaviour the same for valid input.

Fixed (files not touched by #297)

  • flowview_databases.php flowview_get_item_details(): the registry details lookup uses the keys of the row id sent by the browser as column names. Column names can not be bound, so only columns of the table are accepted; any other key returns no row. Reachable with the NetFlow Admin realm.
  • flowview_databases.php view_db_table(), view_dns_cache(), view_routes(): registry, DNS cache and ARIN values (downloaded from external registries) and the Source options were printed without html_escape().
  • flowview_filters.php actions_filters() / show_filters(): the Filter names in the action confirmation and the listener name in the list were printed without html_escape(). The Delete, Disable and Enable actions concatenated the (already validated) ids into SQL; they now use flowview_db_execute_prepared().
  • flowview_process.php: the due-schedule query concatenated the queued ids and the time; it now binds them.
  • flowview_bulkarin.php (CLI): the whois path, provider and CIDR were passed to the shell unescaped; they now go through cacti_escapeshellcmd() / cacti_escapeshellarg().
  • flowview_upgrade.php (CLI): plugin_flowview_version was written straight to settings; it now uses set_config_option().

Reviewed and left

  • $_POST loops over chk_* in flowview_filters.php and flowview_databases.php: the core idiom; each id is checked with input_validate_input_number().
  • db_qstr()-quoted LIKE filters in flowview_databases.php and cli/fixprivate.php: already escaped.
  • DROP TABLE / ALTER TABLE with names from information_schema (flowview_cleanup.php, flowview_drop_raw_tables.php, flowview_process.php, cli/repair_tables.php, cli/fixprivate.php): identifiers from the server, not from a request.
  • flowview_runner.php exec_background() and cli/materialize_queries.php proc_open(): integer ids from the database, and an argument array without a shell.
  • includes/arrays.php:610,618: a translated label inside SQL; not request data.

Also noticed, not changed

  • plugin_flowview_queries has no enabled column, so the Disable and Enable actions of the Filters page fail with an SQL error.
  • flowview_databases.php?action=purge empties the DNS cache on a GET request.
  • view_db_table() reads $tabs[$tab] before checking that the tab exists, which logs PHP warnings when the registry tabs are switched off.

Deferred until #297 merges

#297 changes these files, so they are left alone here to avoid conflicts. Line numbers are from develop.

  • includes/functions.php:8576 (wget download): escape $local_file, $remote_file and each proxy value with cacti_escapeshellarg().
  • includes/functions.php:9114 (whois origin lookup): same change as flowview_bulkarin.php, cacti_escapeshellcmd($whois_path) and cacti_escapeshellarg() for the provider and CIDR.
  • includes/functions.php:9446 (flow-export): cacti_escapeshellcmd($flow_export) and cacti_escapeshellarg($file).
  • flowview_schedules.php:446: flowview_db_fetch_row_prepared('SELECT * FROM plugin_flowview_schedules WHERE id = ?', [$save['id']]).
  • flowview_devices.php:252: flowview_db_fetch_cell_prepared(... WHERE id = ?, [$matches[1]]) and html_escape() on the name.
  • flowview_devices.php:517-522, 747-754, 1053-1064 and flowview_schedules.php:722-728, 1029-1033: html_escape() the text columns (listener and schedule names, addresses, e-mail, sender) passed to form_selectable_cell().
  • includes/functions.php:4696, 4714: direct settings writes for the rematerialize queue. Left as is: the delete is conditional on the stored token, which set_config_option() can not express.
  • flowview.php:301, 450: the whole of $_REQUEST is saved to and restored from the session. Not a raw read, but worth a look when that page is next changed.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions