From d51ecc45544d4c71529380a7664f5514a1349da7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 6 May 2021 20:10:37 +0200 Subject: [PATCH] sources/saml: handle internal error Signed-off-by: Jens Langhammer --- authentik/events/tasks.py | 2 +- authentik/flows/transfer/importer.py | 2 +- authentik/sources/saml/views.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/authentik/events/tasks.py b/authentik/events/tasks.py index 69c84a6fa..994353d2d 100644 --- a/authentik/events/tasks.py +++ b/authentik/events/tasks.py @@ -1,6 +1,6 @@ """Event notification tasks""" from guardian.shortcuts import get_anonymous_user -from structlog import get_logger +from structlog.stdlib import get_logger from authentik.core.models import User from authentik.events.models import ( diff --git a/authentik/flows/transfer/importer.py b/authentik/flows/transfer/importer.py index 5c9fde10e..c9405cada 100644 --- a/authentik/flows/transfer/importer.py +++ b/authentik/flows/transfer/importer.py @@ -13,7 +13,7 @@ from django.db.models.query_utils import Q from django.db.utils import IntegrityError from rest_framework.exceptions import ValidationError from rest_framework.serializers import BaseSerializer, Serializer -from structlog import BoundLogger, get_logger +from structlog.stdlib import BoundLogger, get_logger from authentik.flows.models import Flow, FlowStageBinding, Stage from authentik.flows.transfer.common import ( diff --git a/authentik/sources/saml/views.py b/authentik/sources/saml/views.py index 792cecad2..afd16b38a 100644 --- a/authentik/sources/saml/views.py +++ b/authentik/sources/saml/views.py @@ -11,7 +11,8 @@ from django.utils.http import urlencode from django.utils.translation import gettext_lazy as _ from django.views import View from django.views.decorators.csrf import csrf_exempt -from xmlsec import VerificationError +from structlog.stdlib import get_logger +from xmlsec import InternalError, VerificationError from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes from authentik.flows.models import in_memory_stage @@ -44,6 +45,7 @@ from authentik.stages.consent.stage import ( PLAN_CONTEXT_TITLE = "title" PLAN_CONTEXT_URL = "url" PLAN_CONTEXT_ATTRS = "attrs" +LOGGER = get_logger() class AutosubmitStageView(ChallengeStageView): @@ -125,7 +127,11 @@ class InitiateView(View): final_url = urlunparse(res) return redirect(final_url) # As POST Binding we show a form - saml_request = nice64(auth_n_req.build_auth_n()) + try: + saml_request = nice64(auth_n_req.build_auth_n()) + except InternalError as exc: + LOGGER.warning(str(exc)) + return bad_request_message(request, str(exc)) injected_stages = [] plan_kwargs = { PLAN_CONTEXT_TITLE: _("Redirecting to %(app)s..." % {"app": source.name}),