diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index 54e6f5602..c04f8f423 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -331,7 +331,7 @@ class RSSFeedWidget(DashboardWidget): response = requests.get( url=self.config['feed_url'], headers={'User-Agent': f'NetBox/{settings.RELEASE.version}'}, - proxies=resolve_proxies(url=self.config['feed_url']), + proxies=resolve_proxies(url=self.config['feed_url'], context={'client': self}), timeout=3 ) response.raise_for_status() diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py index 7b1b7a55a..368075217 100644 --- a/netbox/extras/webhooks.py +++ b/netbox/extras/webhooks.py @@ -89,7 +89,7 @@ def send_webhook(event_rule, model_name, event_type, data, timestamp, username, session.verify = webhook.ssl_verification if webhook.ca_file_path: session.verify = webhook.ca_file_path - proxies = resolve_proxies(url=url, context={'webhook': webhook}) + proxies = resolve_proxies(url=url, context={'client': webhook}) response = session.send(prepared_request, proxies=proxies) if 200 <= response.status_code <= 299: diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 748a1edf2..0ad46b21e 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -117,7 +117,7 @@ EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', []) FIELD_CHOICES = getattr(configuration, 'FIELD_CHOICES', {}) FILE_UPLOAD_MAX_MEMORY_SIZE = getattr(configuration, 'FILE_UPLOAD_MAX_MEMORY_SIZE', 2621440) GRAPHQL_MAX_ALIASES = getattr(configuration, 'GRAPHQL_MAX_ALIASES', 10) -HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None) +HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', {}) INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1')) ISOLATED_DEPLOYMENT = getattr(configuration, 'ISOLATED_DEPLOYMENT', False) JINJA2_FILTERS = getattr(configuration, 'JINJA2_FILTERS', {}) @@ -209,7 +209,7 @@ for path in PROXY_ROUTERS: try: import_string(path) except ImportError: - raise ImproperlyConfigured(f"Invalid proxy router path: {path}") + raise ImproperlyConfigured(f"Invalid path in PROXY_ROUTERS: {path}") # diff --git a/netbox/utilities/proxy.py b/netbox/utilities/proxy.py index 85e942a65..8c9e3d196 100644 --- a/netbox/utilities/proxy.py +++ b/netbox/utilities/proxy.py @@ -20,6 +20,15 @@ class DefaultProxyRouter: return urlparse(url).scheme def route(self, url=None, protocol=None, context=None): + """ + Returns the appropriate proxy given a URL or protocol. Arbitrary context data may also be passed where + available. + + Args: + url: The specific request URL for which the proxy will be used (if known) + protocol: The protocol in use (e.g. http or https) (if known) + context: Additional context to aid in proxy selection. May include e.g. the requesting client. + """ if url and protocol is None: protocol = self._get_protocol_from_url(url) if protocol and protocol in settings.HTTP_PROXIES: @@ -42,5 +51,5 @@ def resolve_proxies(url=None, protocol=None, context=None): for item in settings.PROXY_ROUTERS: router = import_string(item) if type(item) is str else item - if proxies := router.route(url=url, protocol=protocol, context=context): + if proxies := router().route(url=url, protocol=protocol, context=context): return proxies