fix(api): enforce POST on SAML ACS endpoint (#12393)

This commit is contained in:
Adrián Peña
2026-08-07 14:24:45 +02:00
committed by GitHub
parent 94594d6766
commit 34b4e6f016
3 changed files with 34 additions and 1 deletions
@@ -0,0 +1 @@
`/api/v1/accounts/saml/{organization_slug}/acs/` rejects non-POST requests before SAML response processing
+31
View File
@@ -14673,6 +14673,37 @@ class TestSAMLConfigurationViewSet:
assert not SAMLConfiguration.objects.filter(id=config.id).exists()
@pytest.mark.django_db
class TestSAMLACSView:
def test_get_is_not_allowed(self, client, saml_setup):
response = client.get(
reverse(
"saml_acs",
kwargs={"organization_slug": saml_setup["domain"]},
)
)
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
assert response.headers["Allow"] == "POST"
assert "saml-acs-session" not in response.cookies
def test_post_is_forwarded_to_allauth(self, client, saml_setup):
response = client.post(
reverse(
"saml_acs",
kwargs={"organization_slug": saml_setup["domain"]},
),
data={"SAMLResponse": "test-saml-response"},
)
assert response.status_code == status.HTTP_302_FOUND
assert response.url == reverse(
"saml_finish_acs",
kwargs={"organization_slug": saml_setup["domain"]},
)
assert "saml-acs-session" in response.cookies
@pytest.mark.django_db
class TestTenantFinishACSView:
def test_dispatch_skips_if_user_not_authenticated(self, monkeypatch):
+2 -1
View File
@@ -46,6 +46,7 @@ from api.v1.views import (
from django.http import JsonResponse
from django.urls import include, path
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from drf_spectacular.views import SpectacularRedocView
from rest_framework_nested import routers
@@ -194,7 +195,7 @@ urlpatterns = [
),
path(
"accounts/saml/<organization_slug>/acs/",
ACSView.as_view(),
require_POST(ACSView.as_view()),
name="saml_acs",
),
path(