Skip to content

Commit

Permalink
enforce server script perms when handling alert templates
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jun 19, 2024
1 parent 559d9b9 commit 711e85e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/tacticalrmm/alerts/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.shortcuts import get_object_or_404
from rest_framework import permissions

from tacticalrmm.constants import AlertTemplateActionType
from tacticalrmm.permissions import _has_perm, _has_perm_on_agent

if TYPE_CHECKING:
Expand Down Expand Up @@ -53,4 +54,17 @@ def has_permission(self, r, view) -> bool:
if r.method == "GET":
return _has_perm(r, "can_list_alerttemplates")

if r.method in ("POST", "PUT", "PATCH"):
# ensure only users with explicit run server script perms can add/modify alert templates
# while also still requiring the manage alert template perm
if isinstance(r.data, dict):
if (
r.data.get("action_type") == AlertTemplateActionType.SERVER
or r.data.get("resolved_action_type")
== AlertTemplateActionType.SERVER
):
return _has_perm(r, "can_run_server_scripts") and _has_perm(
r, "can_manage_alerttemplates"
)

return _has_perm(r, "can_manage_alerttemplates")

0 comments on commit 711e85e

Please sign in to comment.