:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix: use consistent auth class for viewsets (#108872)
Reece Jones3c76856a5042
diff --git a/.semgrep/rules/security/no-drf-session-authentication.yaml b/.semgrep/rules/security/no-drf-session-authentication.yamlnew file mode 100644index 000000000000..32a470c7a4f6--- /dev/null+++ b/.semgrep/rules/security/no-drf-session-authentication.yaml@@ -0,0 +1,40 @@+rules:+ - id: no-drf-session-authentication+ message: |+ Use `posthog.auth.SessionAuthentication` instead of+ `rest_framework.authentication.SessionAuthentication`.++ Only PostHog's subclass enforces org-level Two-Factor Authentication+ (`enforce_two_factor`) and verified-domain checking+ (`enforce_verified_domain`). DRF's class skips both.++ You imported the DRF class. Change to:++ from posthog.auth import SessionAuthentication++ (PostHog's `SessionAuthentication` is a subclass of DRF's, so all+ `isinstance` checks and type annotations remain compatible.)++ Suppress a legitimate exception with:+ `# nosemgrep: no-drf-session-authentication -- <reason>`.+ languages: [python]+ severity: ERROR+ patterns:+ - pattern-either:+ - pattern: from rest_framework.authentication import SessionAuthentication+ - pattern: from rest_framework.authentication import SessionAuthentication as $ALIAS+ - patterns:+ - pattern-inside: |+ from rest_framework import authentication+ ...+ - pattern: authentication.SessionAuthentication+ paths:+ include:+ - common/**/*.py+ - ee/**/*.py+ - posthog/**/*.py+ - products/**/*.py+ exclude:+ - '**/test/**'+ - '**/tests/**'+ - '**/test_*.py'diff --git a/.semgrep/rules/security/tests/no-drf-session-authentication.py b/.semgrep/rules/security/tests/no-drf-session-authentication.pynew file mode 100644index 000000000000..ed8ea5d4cebb--- /dev/null+++ b/.semgrep/rules/security/tests/no-drf-session-authentication.py@@ -0,0 +1,22 @@+# Test cases for no-drf-session-authentication semgrep rule++# ruleid: no-drf-session-authentication+from rest_framework.authentication import SessionAuthentication++# ruleid: no-drf-session-authentication+from rest_framework.authentication import SessionAuthentication as DRFSessionAuth++# ruleid: no-drf-session-authentication+from rest_framework import authentication++# ruleid: no-drf-session-authentication+x = authentication.SessionAuthentication()++# ok: no-drf-session-authentication+from posthog.auth import SessionAuthentication++# ok: no-drf-session-authentication+from rest_framework.authentication import BaseAuthentication++# ok: no-drf-session-authentication+from rest_framework import authentication\ No newline at end of filediff --git a/ee/support_sidebar_max/views.py b/ee/support_sidebar_max/views.pyindex 1424edb0dadc..dc6597f0f598 100644--- a/ee/support_sidebar_max/views.py+++ b/ee/support_sidebar_max/views.py@@ -16,12 +16,12 @@ import posthoganalyticsfrom asgiref.sync import sync_to_asyncfrom posthoganalytics.ai.anthropic import Anthropicfrom rest_framework import status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Response+from posthog.auth import SessionAuthenticationfrom posthog.models import Userfrom ee.support_sidebar_max.prompt import get_system_promptdiff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.pyindex 437d5f645a16..a11b1f0ce695 100644--- a/posthog/api/oauth/test_views.py+++ b/posthog/api/oauth/test_views.py@@ -512,7 +512,7 @@ class TestOAuthAPI(APIBaseTest):self.base_authorization_post_body,)- self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)@time_machine.travel("2025-01-01 00:00:00", tick=False)def test_authorize_post_authorization_granted(self):diff --git a/posthog/api/oauth/views.py b/posthog/api/oauth/views.pyindex 5a16990ddb47..4a2b2acbce1e 100644--- a/posthog/api/oauth/views.py+++ b/posthog/api/oauth/views.py@@ -37,7 +37,6 @@ from oauthlib.common import Request as OauthlibRequestfrom oauthlib.oauth2 import InvalidClientIdError, InvalidGrantErrorfrom redis.exceptions import RedisErrorfrom rest_framework import serializers, status-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.exceptions import NotFoundfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.response import Response@@ -69,6 +68,7 @@ from posthog.api.oauth.metadata import (openid_provider_metadata,protected_resource_metadata,)+from posthog.auth import SessionAuthenticationfrom posthog.helpers.impersonation import get_original_user_from_session, is_impersonated_sessionfrom posthog.helpers.oauth_pending_connection import (PendingOAuthConnection,diff --git a/posthog/auth.py b/posthog/auth.pyindex b943b1788588..e0a07d991636 100644--- a/posthog/auth.py+++ b/posthog/auth.py@@ -170,7 +170,10 @@ class ZxcvbnValidator:)-class SessionAuthentication(ActivityCredentialMixin, authentication.SessionAuthentication):+class SessionAuthentication(+ ActivityCredentialMixin,+ authentication.SessionAuthentication, # nosemgrep: no-drf-session-authentication+):"""This class is needed, because REST Framework's default SessionAuthentication does never return 401's,because they cannot fill the WWW-Authenticate header with a valid value in the 401 response. As adiff --git a/posthog/event_usage.py b/posthog/event_usage.pyindex 4222ac51da82..8c637131bd40 100644--- a/posthog/event_usage.py+++ b/posthog/event_usage.py@@ -11,8 +11,8 @@ from django.contrib.auth.models import AnonymousUserimport posthoganalyticsfrom opentelemetry import trace-from rest_framework.authentication import SessionAuthentication+from posthog.auth import SessionAuthenticationfrom posthog.clickhouse.query_tagging import get_query_tag_valuefrom posthog.constants import POSTHOG_INTERNAL_EMAIL_SUFFIXfrom posthog.helpers.oauth_pending_connection import PendingOAuthConnectiondiff --git a/posthog/test/repo_invariants/setup_import_baseline.txt b/posthog/test/repo_invariants/setup_import_baseline.txtindex 4d3eece7e47f..fbb37eea627b 100644--- a/posthog/test/repo_invariants/setup_import_baseline.txt+++ b/posthog/test/repo_invariants/setup_import_baseline.txt@@ -29,4 +29,6 @@ psycopgredisrichtrio+webauthn+zxcvbn# First-party modules with a known, structural import cost:diff --git a/posthog/test/repo_invariants/test_authentication_credential_types.py b/posthog/test/repo_invariants/test_authentication_credential_types.pyindex ecc6ec17056e..8a7bf80fdc1a 100644--- a/posthog/test/repo_invariants/test_authentication_credential_types.py+++ b/posthog/test/repo_invariants/test_authentication_credential_types.py@@ -22,7 +22,6 @@ import importlibfrom pathlib import Pathfrom typing import get_args-from rest_framework import authenticationfrom rest_framework.authentication import BaseAuthenticationfrom rest_framework.schemas.generators import EndpointEnumeratorfrom rest_framework.views import APIView@@ -34,9 +33,7 @@ SCANNED_ROOTS = ("posthog", "ee", "products", "common")SKIPPED_DIRS = {"node_modules", ".venv", "venv", "__pycache__", ".git", ".mypy_cache"}OWNED_MODULE_PREFIXES = tuple(f"{root}." for root in SCANNED_ROOTS)DECLARED_TYPES = frozenset(get_args(DeclaredCredentialType))-# `ActivityLoggingMiddleware` records the session for any class that authenticates the session's-# user, so DRF's own session class records `session` too.-UNOWNED_ROUTE_CLASSES = frozenset({authentication.SessionAuthentication})+UNOWNED_ROUTE_CLASSES: frozenset[type] = frozenset()def _dotted_name(cls: type) -> str:diff --git a/posthog/test/repo_invariants/test_startup_import_budget.py b/posthog/test/repo_invariants/test_startup_import_budget.pyindex a18ee05cca55..4e8d61526827 100644--- a/posthog/test/repo_invariants/test_startup_import_budget.py+++ b/posthog/test/repo_invariants/test_startup_import_budget.py@@ -49,8 +49,6 @@ FORBIDDEN_AT_SETUP = ["ee.vercel.integration", # reaches ee.api.authentication (@api_view -> DRF schema class) — receivers live in ee.vercel.receivers and import it at call time"posthog.api.documentation", # drf_spectacular schema hooks — request-time only"django.test", # test client — was dragged in by drf_spectacular.plumbing via rest_framework.test- "zxcvbn", # password strength — only posthog.auth needs it, deferred in posthog.helpers.impersonation- "webauthn", # passkeys — same door as zxcvbn (posthog.auth)"posthog.async_migrations.setup", # imports every async migration — only when SKIP_ASYNC_MIGRATIONS_SETUP is off"infi.clickhouse_orm", # ClickHouse ORM — migration commands only; its package __init__ imports pkg_resources"pkg_resources", # setuptools shim (~40ms) — only reached via infi.clickhouse_ormdiff --git a/posthog/test/test_event_usage.py b/posthog/test/test_event_usage.pyindex 28148ca59a69..d1118a342c11 100644--- a/posthog/test/test_event_usage.py+++ b/posthog/test/test_event_usage.py@@ -299,7 +299,7 @@ class TestGetEventSource(BaseTest):assert get_event_source(request) == expecteddef test_web_via_session_authentication(self):- from rest_framework.authentication import SessionAuthentication+ from posthog.auth import SessionAuthenticationrequest = SimpleNamespace(META={}, headers={}, successful_authenticator=SessionAuthentication())assert get_event_source(request) == EventSource.WEBdiff --git a/products/endpoints/backend/logic/execution.py b/products/endpoints/backend/logic/execution.pyindex e4ea861f53a8..2dd6a442bff0 100644--- a/products/endpoints/backend/logic/execution.py+++ b/products/endpoints/backend/logic/execution.py@@ -24,7 +24,6 @@ from asgiref.sync import async_to_syncfrom dateutil.parser import isoparsefrom pydantic import BaseModelfrom rest_framework import status-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.exceptions import Throttled, ValidationErrorfrom rest_framework.request import Requestfrom rest_framework.response import Response@@ -44,6 +43,7 @@ from posthog.hogql.errors import ExposedHogQLError, ResolutionErrorfrom posthog.api.mixins import PydanticModelMixinfrom posthog.api.query import _process_query_requestfrom posthog.api.services.query import process_query_model+from posthog.auth import SessionAuthenticationfrom posthog.clickhouse.client.connection import Workloadfrom posthog.clickhouse.client.limit import ConcurrencyLimitExceededfrom posthog.clickhouse.query_tagging import (diff --git a/products/mcp_store/backend/presentation/gateway_views.py b/products/mcp_store/backend/presentation/gateway_views.pyindex 9ec42e8cf3c1..2b4bcdf6c0c8 100644--- a/products/mcp_store/backend/presentation/gateway_views.py+++ b/products/mcp_store/backend/presentation/gateway_views.py@@ -29,7 +29,6 @@ import structlogfrom drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_field, extend_schema_serializerfrom rest_framework import mixins, serializers, status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDeniedfrom rest_framework.permissions import IsAuthenticated@@ -39,6 +38,7 @@ from rest_framework.response import Responsefrom posthog.api.mixins import validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializer+from posthog.auth import SessionAuthenticationfrom posthog.event_usage import report_user_actionfrom posthog.models import Userfrom posthog.models.organization import OrganizationMembershipdiff --git a/products/mcp_store/backend/presentation/views.py b/products/mcp_store/backend/presentation/views.pyindex 0f931bcabf7f..6c7e7fbcec1f 100644--- a/products/mcp_store/backend/presentation/views.py+++ b/products/mcp_store/backend/presentation/views.py@@ -23,7 +23,6 @@ import structlogfrom drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_fieldfrom rest_framework import mixins, renderers, serializers, status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import PermissionDeniedfrom rest_framework.permissions import IsAuthenticated@@ -32,6 +31,7 @@ from rest_framework.response import Responsefrom posthog.api.mixins import validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin+from posthog.auth import SessionAuthenticationfrom posthog.cdp.services.icons import CDPIconsServicefrom posthog.cloud_utils import is_dev_modefrom posthog.event_usage import report_user_actiondiff --git a/products/signals/backend/scout_chat.py b/products/signals/backend/scout_chat.pyindex 982c2054b4c4..22b4f7174691 100644--- a/products/signals/backend/scout_chat.py+++ b/products/signals/backend/scout_chat.py@@ -15,7 +15,6 @@ from django.core.cache import cachefrom drf_spectacular.utils import OpenApiResponsefrom rest_framework import exceptions, serializers, status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Response@@ -23,7 +22,7 @@ from rest_framework.throttling import UserRateThrottlefrom posthog.api.mixins import validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.models.user import Userfrom posthog.permissions import APIScopePermissiondiff --git a/products/signals/backend/views.py b/products/signals/backend/views.pyindex 1951a5c07a79..a2fb7ca2565e 100644--- a/products/signals/backend/views.py+++ b/products/signals/backend/views.py@@ -39,7 +39,6 @@ from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schefrom opentelemetry import tracefrom pydantic import ValidationError as PydanticValidationErrorfrom rest_framework import exceptions, mixins, serializers, status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFoundfrom rest_framework.permissions import IsAuthenticated@@ -52,7 +51,12 @@ from temporalio.exceptions import WorkflowAlreadyStartedErrorfrom posthog.api.integration import github_rate_limited_responsefrom posthog.api.mixins import ValidatedRequest, validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import InternalAPIAuthentication, OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import (+ InternalAPIAuthentication,+ OAuthAccessTokenAuthentication,+ PersonalAPIKeyAuthentication,+ SessionAuthentication,+)from posthog.dataclasses import frozenfrom posthog.egress.github.transport import GitHubEgressBudgetExhausted, GitHubRateLimitErrorfrom posthog.egress.limiter.policies import Prioritydiff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 0a8e45c298cb..a7005a7ee26f 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -20,7 +20,6 @@ import posthoganalyticsfrom drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schemafrom rest_framework import status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import (APIException,@@ -44,7 +43,7 @@ from posthog.api.pagination import PrecountedLimitOffsetPaginationfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.streaming import sse_streaming_responsefrom posthog.api.utils import ServerTimingsGathered-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.event_usage import groupsfrom posthog.middleware import is_read_only_impersonationfrom posthog.models import Userdiff --git a/products/tasks/backend/presentation/views/channels_api.py b/products/tasks/backend/presentation/views/channels_api.pyindex 70560e3a62bf..f5cd80d9e20b 100644--- a/products/tasks/backend/presentation/views/channels_api.py+++ b/products/tasks/backend/presentation/views/channels_api.py@@ -4,7 +4,6 @@ from uuid import UUIDfrom drf_spectacular.openapi import AutoSchemafrom drf_spectacular.utils import OpenApiResponse, extend_schemafrom rest_framework import status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDenied, ValidationErrorfrom rest_framework.pagination import LimitOffsetPagination@@ -14,7 +13,7 @@ from rest_framework.response import Responsefrom posthog.api.mixins import validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.models import OrganizationMembershipfrom posthog.models.user import Userfrom posthog.permissions import APIScopePermissiondiff --git a/products/tasks/backend/presentation/views/config_api.py b/products/tasks/backend/presentation/views/config_api.pyindex 86f122a44e8f..98b0b151973f 100644--- a/products/tasks/backend/presentation/views/config_api.py+++ b/products/tasks/backend/presentation/views/config_api.py@@ -5,14 +5,14 @@ from django.core.exceptions import ValidationError as DjangoValidationErrorfrom drf_spectacular.utils import extend_schemafrom rest_framework import viewsets-from rest_framework.authentication import SessionAuthentication+from rest_framework.authentication import BaseAuthenticationfrom rest_framework.exceptions import ValidationErrorfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.models.user import Userfrom posthog.permissions import APIScopePermission, TeamMemberStrictManagementPermission@@ -24,7 +24,11 @@ from products.tasks.backend.presentation.serializers import (TasksUserConfigResponseSerializer,)-_AUTH_CLASSES = [SessionAuthentication, PersonalAPIKeyAuthentication, OAuthAccessTokenAuthentication]+_AUTH_CLASSES: list[type[BaseAuthentication]] = [+ SessionAuthentication,+ PersonalAPIKeyAuthentication,+ OAuthAccessTokenAuthentication,+]def _user_id(request: Request) -> int:diff --git a/products/tasks/backend/presentation/views/desktop_access.py b/products/tasks/backend/presentation/views/desktop_access.pyindex f7e5b92a7098..011f1b1dd4dd 100644--- a/products/tasks/backend/presentation/views/desktop_access.py+++ b/products/tasks/backend/presentation/views/desktop_access.py@@ -2,14 +2,13 @@ from typing import Any, castfrom drf_spectacular.utils import OpenApiResponse, extend_schemafrom rest_framework import status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Responsefrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.models import Userfrom posthog.permissions import APIScopePermissiondiff --git a/products/tasks/backend/presentation/views/loops.py b/products/tasks/backend/presentation/views/loops.pyindex 24075b396e81..32c6c64cc3fe 100644--- a/products/tasks/backend/presentation/views/loops.py+++ b/products/tasks/backend/presentation/views/loops.py@@ -3,7 +3,6 @@ import jsonfrom drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiResponse, extend_schemafrom rest_framework import status, viewsets-from rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDenied, ValidationErrorfrom rest_framework.pagination import LimitOffsetPagination@@ -14,7 +13,12 @@ from rest_framework.views import APIViewfrom posthog.api.mixins import validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, ProjectSecretAPIKeyAuthentication+from posthog.auth import (+ OAuthAccessTokenAuthentication,+ PersonalAPIKeyAuthentication,+ ProjectSecretAPIKeyAuthentication,+ SessionAuthentication,+)from posthog.permissions import APIScopePermission, is_authenticated_via_project_secret_api_keyfrom posthog.rate_limit import PersonalOrProjectSecretApiKeyRateThrottle, ProjectSecretApiKeyTeamRateThrottlediff --git a/products/tasks/backend/presentation/views/repo_routing_rules_api.py b/products/tasks/backend/presentation/views/repo_routing_rules_api.pyindex c505327c5b8d..a9cdf9cc0238 100644--- a/products/tasks/backend/presentation/views/repo_routing_rules_api.py+++ b/products/tasks/backend/presentation/views/repo_routing_rules_api.py@@ -4,19 +4,23 @@ from django.db import connection, transactionfrom django.db.models import Max, QuerySetfrom rest_framework import serializers, viewsets-from rest_framework.authentication import SessionAuthentication+from rest_framework.authentication import BaseAuthenticationfrom rest_framework.permissions import SAFE_METHODS, BasePermission, IsAuthenticatedfrom rest_framework.request import Requestfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializer-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthenticationfrom posthog.models.repo_routing_rule import RepoRoutingRulefrom posthog.permissions import APIScopePermissionfrom products.tasks.backend.facade.client_provenance import is_sandbox_oauth_request-_AUTH_CLASSES = [SessionAuthentication, PersonalAPIKeyAuthentication, OAuthAccessTokenAuthentication]+_AUTH_CLASSES: list[type[BaseAuthentication]] = [+ SessionAuthentication,+ PersonalAPIKeyAuthentication,+ OAuthAccessTokenAuthentication,+]# The repo selection prompt truncates each rendered rule at this length, so a longer rule# would silently lose its distinguishing terms. The Slack `rules add` path enforces thediff --git a/products/tasks/backend/tests/test_ai_run_defaults.py b/products/tasks/backend/tests/test_ai_run_defaults.pyindex 095cfd598218..93f0afa673c3 100644--- a/products/tasks/backend/tests/test_ai_run_defaults.py+++ b/products/tasks/backend/tests/test_ai_run_defaults.py@@ -542,9 +542,9 @@ class TestTasksConfigAPI(APIBaseTest):self.client.logout()for path in ("config", "@me/config"):url = f"/api/projects/{self.team.id}/tasks/{path}/"- # 403, not 401: DRF's SessionAuthentication denies without a WWW-Authenticate challenge.- assert self.client.get(url).status_code == 403- assert self.client.post(url, TEAM_TRIPLE).status_code == 403+ # 401, not 403: PostHog's SessionAuthentication sets a WWW-Authenticate challenge.+ assert self.client.get(url).status_code == 401+ assert self.client.post(url, TEAM_TRIPLE).status_code == 401def test_an_outsider_cannot_reach_another_projects_config(self):outsider = User.objects.create_and_join(Organization.objects.create(name="other"), "[email protected]", None)diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex 03587f376f6a..d0b288887c10 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -11541,7 +11541,7 @@ class TestTasksAPIPermissions(BaseTaskAPITest):for url, method in endpoints:response = getattr(self.client, method.lower())(url)- self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, f"Failed for {method} {url}")+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, f"Failed for {method} {url}")def test_cross_team_task_access_forbidden(self):# Create task in other team@@ -17352,7 +17352,7 @@ class TestTaskRunPreviewAPI(BaseTaskAPITest):response = self.client.get(self._preview_url(task, run))- self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)def test_run_detail_reports_whether_a_preview_is_available(self):task = self.create_task()