From 2eee0b87d50c6791e994234a64bf27f07c63cbad Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 2 Aug 2022 10:55:45 -0600 Subject: [PATCH] Include full path when determining proxy host url Session validation includes a method for determining the proxy host url, but previously did not include the path for the initial request. This caused a situation where users with a new session would not be able to complete their first search, since the session validation follow-through url did not include the actual path for their search query. The method now includes a flag for only extracting the root url, which is needed for creating full urls in the content filter. Fixes #708 --- app/utils/misc.py | 6 +++--- app/utils/search.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/utils/misc.py b/app/utils/misc.py index f8d07d9..0ef07c6 100644 --- a/app/utils/misc.py +++ b/app/utils/misc.py @@ -35,11 +35,11 @@ def get_request_url(url: str) -> str: return url -def get_proxy_host_url(r: Request, default: str) -> str: - scheme = r.headers.get('X-Forwarded-Proto', 'http') +def get_proxy_host_url(r: Request, default: str, root=False) -> str: + scheme = r.headers.get('X-Forwarded-Proto', 'https') http_host = r.headers.get('X-Forwarded-Host') if http_host: - return f'{scheme}://{http_host}/' + return f'{scheme}://{http_host}{r.full_path if not root else "/"}' return default diff --git a/app/utils/search.py b/app/utils/search.py index d36c25a..d39e539 100644 --- a/app/utils/search.py +++ b/app/utils/search.py @@ -117,7 +117,10 @@ class Search: """ mobile = 'Android' in self.user_agent or 'iPhone' in self.user_agent # reconstruct url if X-Forwarded-Host header present - root_url = get_proxy_host_url(self.request, self.request.url_root) + root_url = get_proxy_host_url( + self.request, + self.request.url_root, + root=True) content_filter = Filter(self.session_key, root_url=root_url,