Skip to content

Commit 22abf26

Browse files
authored
fix(prompts-activity): Allow org members to write to prompts-activity (#112738)
This PR back in November fixed a vulnerability in prompts-activity: #103753 However, that change also removed the custom permissions which allowed users to use the PUT method. Attempting to dismiss prompts currently results in a 403 unless you have org write access, since it defaults the OrganizationEndpoint permissions.
1 parent c69ad97 commit 22abf26

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/sentry/api/endpoints/prompts_activity.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sentry.api.api_publish_status import ApiPublishStatus
1212
from sentry.api.base import cell_silo_endpoint
1313
from sentry.api.bases import OrganizationEndpoint
14+
from sentry.api.bases.organization import OrganizationPermission
1415
from sentry.models.organization import Organization
1516
from sentry.models.project import Project
1617
from sentry.models.promptsactivity import PromptsActivity
@@ -34,12 +35,20 @@ def validate_feature(self, value):
3435
return value
3536

3637

38+
class PromptsActivityPermission(OrganizationPermission):
39+
scope_map = {
40+
"GET": ["org:read", "org:write", "org:admin"],
41+
"PUT": ["org:read", "org:write", "org:admin"],
42+
}
43+
44+
3745
@cell_silo_endpoint
3846
class PromptsActivityEndpoint(OrganizationEndpoint):
3947
publish_status = {
4048
"GET": ApiPublishStatus.UNKNOWN,
4149
"PUT": ApiPublishStatus.UNKNOWN,
4250
}
51+
permission_classes = (PromptsActivityPermission,)
4352

4453
def get(self, request: Request, organization: Organization, **kwargs) -> Response:
4554
"""Return feature prompt status if dismissed or in snoozed period"""

tests/sentry/api/endpoints/test_prompts_activity.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def test_get_empty_project_id(self) -> None:
5454
class PutPromptsActivityTest(PromptsActivityTestBase):
5555
method = "put"
5656

57+
def test_regular_org_member_can_dismiss(self) -> None:
58+
member_user = self.create_user()
59+
self.create_member(user=member_user, organization=self.org, role="member")
60+
self.login_as(user=member_user)
61+
62+
resp = self.client.put(
63+
self.path,
64+
{
65+
"organization_id": self.org.id,
66+
"feature": "alert_stream",
67+
"status": "dismissed",
68+
},
69+
)
70+
assert resp.status_code == 201
71+
5772
def test_organization_permissions(self) -> None:
5873
new_org = self.create_organization()
5974
self.path = reverse("sentry-api-0-organization-prompts-activity", args=[new_org.slug])

0 commit comments

Comments
 (0)