Skip to content

fix(thold): check graph permission on every threshold action - #940

Open
somethingwithproof wants to merge 11 commits into
Cacti:developfrom
somethingwithproof:fix/threshold-permission-checks
Open

somethingwithproof wants to merge 11 commits into
Cacti:developfrom
somethingwithproof:fix/threshold-permission-checks

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Problem

Some threshold actions checked only the page realm, not whether the logged in user may view the threshold's graph, which the rest of the plugin checks with is_thold_allowed() / is_thold_allowed_graph().

Fix

  • is_thold_allowed_graph() refuses an empty graph id.
  • is_thold_allowed() checks the graph stored on the threshold, or the graph of its data source when the row has none, and refuses when neither resolves. Enable, disable, acknowledge, save and the bulk actions therefore need a graph the user may view.
  • A new threshold is checked like an existing one, and saving requires the chosen data source to be on a viewable graph that matches any submitted graph.
  • The edit form, for an existing or a new threshold, checks the threshold's graph, that the chosen data source item is on it, and (for a new threshold) that the item belongs to the requested data source.
  • host_id is taken from the checked data source (or its graph); the submitted value is used only when neither resolves a device.
  • Creating thresholds from templates checks each graph: thold_create_from_template() (autocreate, the bulk actions, the creation hooks) skips graphs the user may not view with one "Permission Denied" message, and the single-graph template add checks its graph first. With no logged in user (automation, the poller, the command line) nothing changes.

Administrators and users with permission on the graph see no change. A threshold whose row has no graph and whose data source is on no graph can no longer be enabled, disabled or edited by anyone; the existing cleanup removes it with its data source. Reapplying a template's suggested names uses the same resolving check. The shared graph lookup lives in includes/queries.php (thold_resolve_graph_id(), thold_threshold_graph_id(), thold_edit_allowed()).

Verification

  • tests/Unit/ThresholdObjectAuthorizationTest.php (37 tests) covers each check, a device with mixed permissions, thresholds with no stored graph, and the no-session case; the new tests fail without the change.
  • Full Pest suite on PHP 8.3: 765 passed, 1 skipped. Changed-line coverage 100% (thold.php runs at load time and is not in the coverage report, so its two edit-form call sites are covered through thold_edit_allowed()). check-i18n-pot.php passes; cacti.pot gains one string ("You are not authorized to access this Threshold.").
  • On Cacti 1.2.32 (PHP 8.2, MariaDB) with an administrator and a user who has the Configure Thresholds realm and permission on one device: that user can still enable, disable, edit, save, add from a template and autocreate on their own device; each of these is refused on the other device, including for a threshold with no stored graph; the administrator is unaffected.
  • Not exercised live: the data source and graph bulk actions, the creation hooks, and authentication method "None" (unit tests only).

Touches includes/threshold_api.php, thold.php, includes/templates.php and tests/bootstrap-unit.php, which #922, #923 and #928 also edit; the branch merges cleanly with each of them. cacti.pot may need regenerating after #928, whichever merges second.

CHANGELOG line for the release PR:
* issue#939: Check graph permission on every threshold action and take a threshold's device from its data source

Fixes #939

The enable and disable actions now require the threshold's graph to be
one the user may view (is_thold_allowed()), as the acknowledgment
actions already do.

Adds a shared is_graph_allowed() test stub and coverage.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
save_thold() checked graph permission only when updating an existing
threshold. The same is_thold_allowed_graph() check now applies to a new
threshold. The wizard's first save still passes because it carries no
graph yet.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold_edit() now resolves the threshold's graph (from its data source
when the row has none) and redirects with a message when the user may
not view it. A threshold that resolves to no graph is refused.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…a source

save_thold() now checks an existing threshold against the graph stored
on its row, and requires the chosen data source to be on a graph the
user may view and that matches any submitted graph. A data source that
resolves to no graph is refused.

Extends the is_graph_allowed() test stub with a per-graph allow list.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
save_thold() now sets host_id from the checked data source (or its
graph) and uses the submitted value only when neither resolves a device.
The device is used when alerts are evaluated and notifications are
built, so it should come from the data the threshold watches.

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

thold_create_from_template(), used by autocreate, the device, graph and
data source actions and the device and graph creation hooks, now skips
a graph the logged in user may not view and raises one "Permission
Denied" message. Calls with no logged in user (automation, the poller
and the command line) are unchanged.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
is_thold_allowed_graph() now refuses an empty graph id. is_thold_allowed()
checks the graph stored on the threshold's row, or the graph of its data
source when the row has none, and refuses when neither resolves. The
enable, disable, acknowledge, save and bulk actions use it.

thold_add_graphs_action_execute() checks the graph before creating
thresholds from a template. The edit form for a new threshold checks the
requested graph and that the chosen data source is on it, using the same
check as the form for an existing threshold.

The authorization tests cover each of these and share their request and
data source setup through helpers.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ied references

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

The edit form for a new threshold now also checks that the chosen data
source item belongs to the requested data source, which the form
describes, as well as being on the checked graph.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Reapplying a template's suggested names checked the graph stored on each
threshold row, which is now refused when empty. It now uses
is_thold_allowed(), which resolves the graph from the data source when
the row has none, so thresholds without a stored graph are renamed again.

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

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

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.

Check graph permission on every threshold action

1 participant