Skip to content

: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.

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.yaml
new file mode 100644
index 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.py
new file mode 100644
index 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 file
diff --git a/ee/support_sidebar_max/views.py b/ee/support_sidebar_max/views.py
index 1424edb0dadc..dc6597f0f598 100644
--- a/ee/support_sidebar_max/views.py
+++ b/ee/support_sidebar_max/views.py
@@ -16,12 +16,12 @@ import posthoganalytics
from asgiref.sync import sync_to_async
from posthoganalytics.ai.anthropic import Anthropic
from rest_framework import status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
+from posthog.auth import SessionAuthentication
from posthog.models import User
from ee.support_sidebar_max.prompt import get_system_prompt
diff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.py
index 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.py
index 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 OauthlibRequest
from oauthlib.oauth2 import InvalidClientIdError, InvalidGrantError
from redis.exceptions import RedisError
from rest_framework import serializers, status
-from rest_framework.authentication import SessionAuthentication
from rest_framework.exceptions import NotFound
from rest_framework.permissions import IsAuthenticated
from 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 SessionAuthentication
from posthog.helpers.impersonation import get_original_user_from_session, is_impersonated_session
from posthog.helpers.oauth_pending_connection import (
PendingOAuthConnection,
diff --git a/posthog/auth.py b/posthog/auth.py
index 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 a
diff --git a/posthog/event_usage.py b/posthog/event_usage.py
index 4222ac51da82..8c637131bd40 100644
--- a/posthog/event_usage.py
+++ b/posthog/event_usage.py
@@ -11,8 +11,8 @@ from django.contrib.auth.models import AnonymousUser
import posthoganalytics
from opentelemetry import trace
-from rest_framework.authentication import SessionAuthentication
+from posthog.auth import SessionAuthentication
from posthog.clickhouse.query_tagging import get_query_tag_value
from posthog.constants import POSTHOG_INTERNAL_EMAIL_SUFFIX
from posthog.helpers.oauth_pending_connection import PendingOAuthConnection
diff --git a/posthog/test/repo_invariants/setup_import_baseline.txt b/posthog/test/repo_invariants/setup_import_baseline.txt
index 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 @@ psycopg
redis
rich
trio
+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.py
index 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 importlib
from pathlib import Path
from typing import get_args
-from rest_framework import authentication
from rest_framework.authentication import BaseAuthentication
from rest_framework.schemas.generators import EndpointEnumerator
from 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.py
index 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_orm
diff --git a/posthog/test/test_event_usage.py b/posthog/test/test_event_usage.py
index 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) == expected
def test_web_via_session_authentication(self):
- from rest_framework.authentication import SessionAuthentication
+ from posthog.auth import SessionAuthentication
request = SimpleNamespace(META={}, headers={}, successful_authenticator=SessionAuthentication())
assert get_event_source(request) == EventSource.WEB
diff --git a/products/endpoints/backend/logic/execution.py b/products/endpoints/backend/logic/execution.py
index 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_sync
from dateutil.parser import isoparse
from pydantic import BaseModel
from rest_framework import status
-from rest_framework.authentication import SessionAuthentication
from rest_framework.exceptions import Throttled, ValidationError
from rest_framework.request import Request
from rest_framework.response import Response
@@ -44,6 +43,7 @@ from posthog.hogql.errors import ExposedHogQLError, ResolutionError
from posthog.api.mixins import PydanticModelMixin
from posthog.api.query import _process_query_request
from posthog.api.services.query import process_query_model
+from posthog.auth import SessionAuthentication
from posthog.clickhouse.client.connection import Workload
from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded
from posthog.clickhouse.query_tagging import (
diff --git a/products/mcp_store/backend/presentation/gateway_views.py b/products/mcp_store/backend/presentation/gateway_views.py
index 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 structlog
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_field, extend_schema_serializer
from rest_framework import mixins, serializers, status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound, PermissionDenied
from rest_framework.permissions import IsAuthenticated
@@ -39,6 +38,7 @@ from rest_framework.response import Response
from posthog.api.mixins import validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
+from posthog.auth import SessionAuthentication
from posthog.event_usage import report_user_action
from posthog.models import User
from posthog.models.organization import OrganizationMembership
diff --git a/products/mcp_store/backend/presentation/views.py b/products/mcp_store/backend/presentation/views.py
index 0f931bcabf7f..6c7e7fbcec1f 100644
--- a/products/mcp_store/backend/presentation/views.py
+++ b/products/mcp_store/backend/presentation/views.py
@@ -23,7 +23,6 @@ import structlog
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_field
from rest_framework import mixins, renderers, serializers, status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
@@ -32,6 +31,7 @@ from rest_framework.response import Response
from posthog.api.mixins import validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
+from posthog.auth import SessionAuthentication
from posthog.cdp.services.icons import CDPIconsService
from posthog.cloud_utils import is_dev_mode
from posthog.event_usage import report_user_action
diff --git a/products/signals/backend/scout_chat.py b/products/signals/backend/scout_chat.py
index 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 cache
from drf_spectacular.utils import OpenApiResponse
from rest_framework import exceptions, serializers, status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
@@ -23,7 +22,7 @@ from rest_framework.throttling import UserRateThrottle
from posthog.api.mixins import validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.models.user import User
from posthog.permissions import APIScopePermission
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 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_sche
from opentelemetry import trace
from pydantic import ValidationError as PydanticValidationError
from rest_framework import exceptions, mixins, serializers, status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound
from rest_framework.permissions import IsAuthenticated
@@ -52,7 +51,12 @@ from temporalio.exceptions import WorkflowAlreadyStartedError
from posthog.api.integration import github_rate_limited_response
from posthog.api.mixins import ValidatedRequest, validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.auth import InternalAPIAuthentication, OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import (
+ InternalAPIAuthentication,
+ OAuthAccessTokenAuthentication,
+ PersonalAPIKeyAuthentication,
+ SessionAuthentication,
+)
from posthog.dataclasses import frozen
from posthog.egress.github.transport import GitHubEgressBudgetExhausted, GitHubRateLimitError
from posthog.egress.limiter.policies import Priority
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index 0a8e45c298cb..a7005a7ee26f 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -20,7 +20,6 @@ import posthoganalytics
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from rest_framework import status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import (
APIException,
@@ -44,7 +43,7 @@ from posthog.api.pagination import PrecountedLimitOffsetPagination
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.streaming import sse_streaming_response
from posthog.api.utils import ServerTimingsGathered
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.event_usage import groups
from posthog.middleware import is_read_only_impersonation
from posthog.models import User
diff --git a/products/tasks/backend/presentation/views/channels_api.py b/products/tasks/backend/presentation/views/channels_api.py
index 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 UUID
from drf_spectacular.openapi import AutoSchema
from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework import status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError
from rest_framework.pagination import LimitOffsetPagination
@@ -14,7 +13,7 @@ from rest_framework.response import Response
from posthog.api.mixins import validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.models import OrganizationMembership
from posthog.models.user import User
from posthog.permissions import APIScopePermission
diff --git a/products/tasks/backend/presentation/views/config_api.py b/products/tasks/backend/presentation/views/config_api.py
index 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 DjangoValidationError
from drf_spectacular.utils import extend_schema
from rest_framework import viewsets
-from rest_framework.authentication import SessionAuthentication
+from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import ValidationError
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.models.user import User
from 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.py
index 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, cast
from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework import status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.models import User
from posthog.permissions import APIScopePermission
diff --git a/products/tasks/backend/presentation/views/loops.py b/products/tasks/backend/presentation/views/loops.py
index 24075b396e81..32c6c64cc3fe 100644
--- a/products/tasks/backend/presentation/views/loops.py
+++ b/products/tasks/backend/presentation/views/loops.py
@@ -3,7 +3,6 @@ import json
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework import status, viewsets
-from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError
from rest_framework.pagination import LimitOffsetPagination
@@ -14,7 +13,12 @@ from rest_framework.views import APIView
from posthog.api.mixins import validated_request
from 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_key
from posthog.rate_limit import PersonalOrProjectSecretApiKeyRateThrottle, ProjectSecretApiKeyTeamRateThrottle
diff --git a/products/tasks/backend/presentation/views/repo_routing_rules_api.py b/products/tasks/backend/presentation/views/repo_routing_rules_api.py
index 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, transaction
from django.db.models import Max, QuerySet
from rest_framework import serializers, viewsets
-from rest_framework.authentication import SessionAuthentication
+from rest_framework.authentication import BaseAuthentication
from rest_framework.permissions import SAFE_METHODS, BasePermission, IsAuthenticated
from rest_framework.request import Request
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
-from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication
+from posthog.auth import OAuthAccessTokenAuthentication, PersonalAPIKeyAuthentication, SessionAuthentication
from posthog.models.repo_routing_rule import RepoRoutingRule
from posthog.permissions import APIScopePermission
from 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 the
diff --git a/products/tasks/backend/tests/test_ai_run_defaults.py b/products/tasks/backend/tests/test_ai_run_defaults.py
index 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 == 401
def 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.py
index 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()