From b584f092237a6ee63968148c82da2ae8bca0371f Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 11 Jan 2022 15:32:04 -0500 Subject: [PATCH] Fixes #8319: Custom URL fields should honor ALLOWED_URL_SCHEMES config parameter --- docs/release-notes/version-3.1.md | 1 + netbox/utilities/validators.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 88a33b923..898d77437 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -18,6 +18,7 @@ * [#8306](https://github.com/netbox-community/netbox/issues/8306) - Redirect user to previous page after login * [#8314](https://github.com/netbox-community/netbox/issues/8314) - Prevent custom fields with default values from appearing as applied filters erroneously * [#8317](https://github.com/netbox-community/netbox/issues/8317) - Fix CSV import of multi-select custom field values +* [#8319](https://github.com/netbox-community/netbox/issues/8319) - Custom URL fields should honor `ALLOWED_URL_SCHEMES` config parameter --- diff --git a/netbox/utilities/validators.py b/netbox/utilities/validators.py index 5fce17a3a..9c3413893 100644 --- a/netbox/utilities/validators.py +++ b/netbox/utilities/validators.py @@ -20,11 +20,13 @@ class EnhancedURLValidator(URLValidator): r'(?::\d{2,5})?' # Port number r'(?:[/?#][^\s]*)?' # Path r'\Z', re.IGNORECASE) + schemes = None - def __init__(self, schemes=None, **kwargs): - super().__init__(**kwargs) - if schemes is not None: + def __call__(self, value): + if self.schemes is None: + # We can't load the allowed schemes until the configuration has been initialized self.schemes = get_config().ALLOWED_URL_SCHEMES + return super().__call__(value) class ExclusionValidator(BaseValidator):