From 86f9056d3fe59c6b7a125a6289d745163776e985 Mon Sep 17 00:00:00 2001 From: Jens L Date: Wed, 15 Mar 2023 12:00:57 +0100 Subject: [PATCH] core: fix url validator (#4957) Signed-off-by: Jens Langhammer --- authentik/core/tests/test_applications_api.py | 4 ++-- authentik/lib/models.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/authentik/core/tests/test_applications_api.py b/authentik/core/tests/test_applications_api.py index 5c485ea68..587e3a3d2 100644 --- a/authentik/core/tests/test_applications_api.py +++ b/authentik/core/tests/test_applications_api.py @@ -43,14 +43,14 @@ class TestApplicationsAPI(APITestCase): self.assertEqual( self.client.patch( reverse("authentik_api:application-detail", kwargs={"slug": self.allowed.slug}), - {"meta_launch_url": "https://%(username)s.test.goauthentik.io/%(username)s"}, + {"meta_launch_url": "https://%(username)s-test.test.goauthentik.io/%(username)s"}, ).status_code, 200, ) self.allowed.refresh_from_db() self.assertEqual( self.allowed.get_launch_url(self.user), - f"https://{self.user.username}.test.goauthentik.io/{self.user.username}", + f"https://{self.user.username}-test.test.goauthentik.io/{self.user.username}", ) def test_set_icon(self): diff --git a/authentik/lib/models.py b/authentik/lib/models.py index 24054d9e2..19029c57f 100644 --- a/authentik/lib/models.py +++ b/authentik/lib/models.py @@ -81,7 +81,8 @@ class DomainlessFormattedURLValidator(DomainlessURLValidator): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - self.host_re = r"([%\(\)a-zA-Z])+" + self.domain_re + self.domain_re + self.formatter_re = r"([%\(\)a-zA-Z])*" + self.host_re = "(" + self.formatter_re + self.hostname_re + self.domain_re + "|localhost)" self.regex = _lazy_re_compile( r"^(?:[a-z0-9.+-]*)://" # scheme is validated separately r"(?:[^\s:@/]+(?::[^\s:@/]*)?@)?" # user:pass authentication