Skip to content

Conversation

@oioki
Copy link
Member

@oioki oioki commented Dec 1, 2025

The previous fix (#86315) did not really fix the issue.
Here we're reusing check_can_create_alert method first implemented in #79624

Also, for the OrganizationAlertRuleIndexEndpoint.post method I extracted the following logic because it is only related to metric detectors:
https://github.com/getsentry/sentry/pull/97445/files#diff-7ce0c5c5a5e204143274734b7e9a288cd70a869fa5d460e99eee830e44cda682

@oioki oioki requested review from a team as code owners December 1, 2025 18:03
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 1, 2025

# team admins should be able to create alerts for the projects they have access to
# Verify that get_projects is available (requires OrganizationEndpoint)
if not hasattr(self, "get_projects"):
Copy link
Member

Choose a reason for hiding this comment

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

Should we record a sentry error here? Since presumably if this happens it means we’ve implemented things wrong (not extending organization endpoint)

@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...cidents/endpoints/organization_alert_rule_index.py 78.94% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104171      +/-   ##
===========================================
+ Coverage   80.04%    80.71%   +0.67%     
===========================================
  Files        9332      9369      +37     
  Lines      398425    402381    +3956     
  Branches    25480     25480              
===========================================
+ Hits       318908    324787    +5879     
+ Misses      79067     77144    -1923     
  Partials      450       450              

@getsantry
Copy link
Contributor

getsantry bot commented Jan 9, 2026

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Jan 9, 2026
"""
Create a new monitor.
"""
self.check_can_create_alert(request, organization)

This comment was marked as outdated.

@getsantry getsantry bot removed the Stale label Jan 10, 2026
)
# all() returns True for empty list, so include a check for it
if not team_admin_has_access or not projects:
raise PermissionDenied
Copy link
Contributor

Choose a reason for hiding this comment

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

Permission check validates all projects, not the requested one

Medium Severity

The check_can_create_alert method calls self.get_projects(request, organization) without passing the target project, which returns ALL accessible projects rather than the project specified in the POST body. The subsequent check verifies alerts:write permission on ALL returned projects using all(). This causes users with mixed team permissions (team admin on some projects, regular member on others) to be incorrectly denied when trying to create a monitor for a project they DO have admin access to, because the permission check fails on the other projects where they only have member access.

Additional Locations (1)

Fix in Cursor Fix in Web

return

# team admins should be able to create alerts for the projects they have access to
projects = self.get_projects(request, organization)
Copy link
Member

Choose a reason for hiding this comment

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

Does this get all projects the user has access to, or just the projects in the current url params selection?

Copy link
Member Author

Choose a reason for hiding this comment

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

Returns all project ids that the user can access within this organization:
https://github.com/getsentry/sentry/blob/master/src/sentry/api/bases/organization.py#L355-L369

Btw this is not the new code, it was moved from OrganizationAlertRuleIndexEndpoint.check_can_create_alert
https://github.com/getsentry/sentry/pull/104171/changes#diff-7ce0c5c5a5e204143274734b7e9a288cd70a869fa5d460e99eee830e44cda682L627-L628

@oioki oioki requested a review from evanpurkhiser January 12, 2026 15:24
@oioki oioki merged commit f6609a6 into master Jan 12, 2026
66 checks passed
@oioki oioki deleted the fix/cron-check-can-create-alert branch January 12, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants