fix(api): Tighten alert mutation write scopes#113194
Conversation
Require project-scoped write access for alert-style mutation endpoints across alerts, monitors, workflow engine, seer, uptime, replays, and related API surfaces. This keeps the intended write-scope behavior while rebuilding the change directly on master instead of depending on the readonly-mutation-notes stack. Add regression coverage for token and team-admin scope checks, plus the endpoint-specific edge cases that surfaced while unstacking the branch. Co-Authored-By: OpenAI Codex <noreply@openai.com>
Keep missing alert-rule and detector detail lookups on the existing 404 path for project-scoped alerts:write callers. The permission helper now distinguishes a lookup miss from a view that does not participate in project-scoped alert checks, and the detail endpoint tests cover both the missing-target 404 and cross-project 403 behaviors. Co-Authored-By: OpenAI Codex <noreply@openai.com>
Continue the feedback pass by keeping workflow-engine detector lookups reachable from the organization alert-rule detail endpoint. The project-scoped permission helper now preserves the 404 behavior for real lookup misses without short-circuiting the detector fallback path, and the alert-rule detail tests cover the team-admin workflow-engine detector cases explicitly. Also fold the duplicated organization-id helper into a shared location and reuse the alert-rule permission implementation for detector endpoints to avoid the same drift in future changes. Co-Authored-By: OpenAI Codex <noreply@openai.com>
1d18443 to
aec2a3d
Compare
Route get_alert_mutation_projects through _get_organization_id so the\norganization-scoped alert permission check still works when auth token\nevaluation passes an RpcUserOrganizationContext.\n\nAdd a regression test for the RPC wrapper path so the mutation lookup\ndoes not silently return None again.\n\nCo-Authored-By: Codex <noreply@openai.com>
Return ALERT_MUTATION_LOOKUP_MISS for invalid and missing anomaly\npreview project IDs so project-scoped alerts:write callers follow the\nmissing-target path instead of falling through to team fallback.\n\nTighten the related permission narrowing and test annotations so the\nbackend typing job matches the runtime behavior again.\n\nCo-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit eafc40f. Configure here.
| return Response( | ||
| {"detail": "You do not have permission to perform this action."}, | ||
| status=403, | ||
| ) |
There was a problem hiding this comment.
Anomaly preview returns misleading 403 for nonexistent projects
Medium Severity
When a user with org-level write access (e.g., org:admin or org:write) passes the permission check via super().has_object_permission(), the get_alert_mutation_projects method is never called. If the project_id in the request body refers to a project that doesn't exist in the organization, the post() method now returns a 403 with "You do not have permission to perform this action." The old code returned a 400 with "Invalid project," which was more accurate — the user clearly has permission, the project just doesn't exist. This misleads authorized callers into thinking they lack access rather than having submitted an invalid project ID.
Reviewed by Cursor Bugbot for commit eafc40f. Configure here.


Tighten project-scoped write checks for alert-style mutation endpoints that target a specific project.
This rebuilds the intended scope-tightening work from #113120 directly on
masterso it can land without the unrelated readonly-mutation-notes changes that were stacked into the old branch.The main change is to honor project-scoped
alerts:writeaccess consistently across alert-rule and detector mutations, monitor creation, uptime previews and suggestions, replay deletes, data export authorization, user issue mutation, and Seer anomaly preview requests. While tightening those checks, this keeps the established missing-target behavior for alert-rule and detector detail flows instead of turning stale or nonexistent targets into generic permission failures. The Seer anomaly preview follow-up also preserves lookup-miss handling when the permission layer receives anRpcUserOrganizationContext.This also updates regression coverage around project-scoped writers, missing targets, cross-project access, and the anomaly-preview permission path so the permission logic and endpoint behavior stay aligned.
The optional OpenAPI schema-diff check is expected on this PR because these permission changes intentionally update the documented security requirements for the affected endpoints.
Supersedes #113120.