diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index 60da2bd88..67d56c03a 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -1,5 +1,6 @@ """prompt models""" from base64 import b64decode +from binascii import Error from typing import Any, Optional from urllib.parse import urlparse from uuid import uuid4 @@ -90,7 +91,11 @@ class InlineFileField(CharField): _mime, _, enc = header.partition(";") if enc != "base64": raise ValidationError("Invalid encoding") - data = b64decode(encoded.encode()).decode() + try: + data = b64decode(encoded.encode()).decode() + except (UnicodeDecodeError, UnicodeEncodeError, ValueError, Error): + LOGGER.info("failed to decode base64 of file field, keeping base64") + data = encoded return super().to_internal_value(data) diff --git a/authentik/stages/prompt/tests.py b/authentik/stages/prompt/tests.py index 8a3931548..5258b8975 100644 --- a/authentik/stages/prompt/tests.py +++ b/authentik/stages/prompt/tests.py @@ -120,6 +120,10 @@ class TestPromptStage(FlowTestCase): InlineFileField().to_internal_value("data:mine/type;base64,Zm9v"), "foo", ) + self.assertEqual( + InlineFileField().to_internal_value("data:mine/type;base64,Zm9vqwer"), + "Zm9vqwer", + ) def test_render(self): """Test render of form, check if all prompts are rendered correctly"""