From 90cf2d7de35118d25aed793ba9650eb93e0cc169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20F=C3=BCl=C3=B6p?= Date: Tue, 28 Jun 2022 09:04:04 +0000 Subject: [PATCH] Use X-Forwarded-Host as url_root when present If Whoogle is accessed on a non-standard port _and_ proxied, this port is lost to the application and `element['src']`s are incorrectly formed (omitting port). HTTP x-Forwarded-Host will conain this front port number in a typical Nginx reverse proxy configuratoin. --- app/utils/search.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/utils/search.py b/app/utils/search.py index ada83f4..d42593f 100644 --- a/app/utils/search.py +++ b/app/utils/search.py @@ -116,6 +116,14 @@ class Search: """ mobile = 'Android' in self.user_agent or 'iPhone' in self.user_agent + # reconstruct url_root if X-Forwarded-Host header present + scheme = self.request.headers.get('X-Forwarded-Proto', 'http') + http_host = self.request.headers.get('X-Forwarded-Host') + if http_host: + root_url = f'{scheme}://{http_host}/' + else: + root_url = self.request.url_root + content_filter = Filter(self.session_key, root_url=self.request.url_root, mobile=mobile,