Skip to content

Commit d7c6111

Browse files
authored
chore(auth-v2): record analytics for rotating csrf token (#96677)
1 parent b9b17a7 commit d7c6111

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/sentry/analytics/events/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .alert_sent import * # noqa: F401,F403
77
from .api_token_created import * # noqa: F401,F403
88
from .api_token_deleted import * # noqa: F401,F403
9+
from .auth_v2 import * # noqa: F401,F403
910
from .checkin_processing_error_stored import * # noqa: F401,F403
1011
from .codeowners_assignment import * # noqa: F401,F403
1112
from .codeowners_created import * # noqa: F401,F403
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from sentry import analytics
2+
from sentry.analytics import Event, eventclass
3+
4+
5+
@eventclass("auth_v2.csrf_token.rotated")
6+
class AuthV2CsrfTokenRotated(Event):
7+
event: str
8+
9+
10+
@eventclass("auth_v2.csrf_token.delete_login")
11+
class AuthV2DeleteLogin(Event):
12+
event: str
13+
14+
15+
analytics.register(AuthV2CsrfTokenRotated)
16+
analytics.register(AuthV2DeleteLogin)

src/sentry/api/endpoints/auth_index.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from rest_framework.request import Request
1111
from rest_framework.response import Response
1212

13+
from sentry import analytics
14+
from sentry.analytics.events.auth_v2 import AuthV2DeleteLogin
1315
from sentry.api.api_owners import ApiOwner
1416
from sentry.api.api_publish_status import ApiPublishStatus
1517
from sentry.api.authentication import QuietBasicAuthentication
@@ -328,6 +330,13 @@ def delete(self, request: Request, *args, **kwargs) -> Response:
328330
response.delete_cookie(settings.CSRF_COOKIE_NAME, domain=settings.CSRF_COOKIE_DOMAIN)
329331
response.delete_cookie(settings.SESSION_COOKIE_NAME, domain=settings.SESSION_COOKIE_DOMAIN)
330332

333+
if referrer := request.GET.get("referrer"):
334+
analytics.record(
335+
AuthV2DeleteLogin(
336+
event=referrer,
337+
)
338+
)
339+
331340
if slo_url:
332341
response.status_code = status.HTTP_200_OK
333342
response.data = {"sloUrl": slo_url}

src/sentry/auth_v2/endpoints/csrf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from drf_spectacular.utils import extend_schema
55
from rest_framework import status
66

7+
from sentry import analytics
8+
from sentry.analytics.events.auth_v2 import AuthV2CsrfTokenRotated
79
from sentry.api.api_owners import ApiOwner
810
from sentry.api.api_publish_status import ApiPublishStatus
911
from sentry.api.base import Endpoint, control_silo_endpoint
@@ -65,6 +67,13 @@ def get(self, request, *args, **kwargs):
6567
@method_decorator(ensure_csrf_cookie)
6668
def put(self, request, *args, **kwargs):
6769
rotate_token(request)
70+
if referrer := request.GET.get("referrer"):
71+
analytics.record(
72+
AuthV2CsrfTokenRotated(
73+
event=referrer,
74+
)
75+
)
76+
6877
return self.respond(
6978
{
7079
"detail": "Rotated CSRF cookie",

0 commit comments

Comments
 (0)