Skip to content

Commit fd778b1

Browse files
authored
sources/saml: prevent authnrequest signature being inside body on redirect (#19898)
* fix for main * fix for main * fix processor and tests
1 parent d8f6a97 commit fd778b1

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

authentik/providers/saml/tests/test_auth_n_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from authentik.providers.saml.processors.assertion import AssertionProcessor
3030
from authentik.providers.saml.processors.authn_request_parser import AuthNRequestParser
3131
from authentik.sources.saml.exceptions import MismatchedRequestID
32-
from authentik.sources.saml.models import SAMLSource
32+
from authentik.sources.saml.models import SAMLBindingTypes, SAMLSource
3333
from authentik.sources.saml.processors.request import SESSION_KEY_REQUEST_ID, RequestProcessor
3434
from authentik.sources.saml.processors.response import ResponseProcessor
3535

@@ -104,6 +104,7 @@ def setUp(self):
104104
signing_kp=self.cert,
105105
verification_kp=self.cert,
106106
signed_assertion=True,
107+
binding_type=SAMLBindingTypes.POST,
107108
)
108109

109110
def test_signed_valid(self):

authentik/providers/saml/tests/test_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from authentik.providers.saml.models import SAMLPropertyMapping, SAMLProvider
1313
from authentik.providers.saml.processors.assertion import AssertionProcessor
1414
from authentik.providers.saml.processors.authn_request_parser import AuthNRequestParser
15-
from authentik.sources.saml.models import SAMLSource
15+
from authentik.sources.saml.models import SAMLBindingTypes, SAMLSource
1616
from authentik.sources.saml.processors.request import RequestProcessor
1717

1818

@@ -35,6 +35,7 @@ def setUp(self):
3535
issuer="authentik",
3636
signing_kp=cert,
3737
pre_authentication_flow=create_test_flow(),
38+
binding_type=SAMLBindingTypes.POST,
3839
)
3940
self.request_factory = RequestFactory()
4041

authentik/sources/saml/processors/request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from authentik.providers.saml.utils import get_random_id
2121
from authentik.providers.saml.utils.encoding import deflate_and_base64_encode
2222
from authentik.providers.saml.utils.time import get_time_string
23-
from authentik.sources.saml.models import SAMLSource
23+
from authentik.sources.saml.models import SAMLBindingTypes, SAMLSource
2424

2525
SESSION_KEY_REQUEST_ID = "authentik/sources/saml/request_id"
2626

@@ -70,7 +70,7 @@ def get_auth_n(self) -> Element:
7070
# Create issuer object
7171
auth_n_request.append(self.get_issuer())
7272

73-
if self.source.signing_kp:
73+
if self.source.signing_kp and self.source.binding_type != SAMLBindingTypes.REDIRECT:
7474
sign_algorithm_transform = SIGN_ALGORITHM_TRANSFORM_MAP.get(
7575
self.source.signature_algorithm, xmlsec.constants.TransformRsaSha1
7676
)
@@ -91,7 +91,7 @@ def build_auth_n(self) -> str:
9191
(used for POST Bindings)"""
9292
auth_n_request = self.get_auth_n()
9393

94-
if self.source.signing_kp:
94+
if self.source.signing_kp and self.source.binding_type != SAMLBindingTypes.REDIRECT:
9595
xmlsec.tree.add_ids(auth_n_request, ["ID"])
9696

9797
ctx = xmlsec.SignatureContext()

0 commit comments

Comments
 (0)