From b288393cd4f416bba4ad0e10fe12c30515b3987c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 22 Jan 2023 00:03:39 +0100 Subject: [PATCH] stages/invitation: handle incorrectly formatted token closes #4481 Signed-off-by: Jens Langhammer --- authentik/stages/invitation/stage.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/authentik/stages/invitation/stage.py b/authentik/stages/invitation/stage.py index 3fc13cc16..8c2c59ded 100644 --- a/authentik/stages/invitation/stage.py +++ b/authentik/stages/invitation/stage.py @@ -2,6 +2,7 @@ from typing import Optional from deepmerge import always_merger +from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext_lazy as _ @@ -41,7 +42,11 @@ class InvitationStageView(StageView): token = self.get_token() if not token: return None - invite: Invitation = Invitation.objects.filter(pk=token).first() + try: + invite: Invitation = Invitation.objects.filter(pk=token).first() + except ValidationError: + self.logger.debug("invalid invitation", token=token) + return None if not invite: self.logger.debug("invalid invitation", token=token) return None