From bbbe6b21eadd760e553bd9f50bfedcdf2afac491 Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@libreserver.org> Date: Mon, 9 Jan 2023 22:49:17 +0000 Subject: [PATCH] Redirect parameter --- daemon.py | 10 +++++++--- webfinger.py | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon.py b/daemon.py index 4c79fdbba..fa2fc9763 100644 --- a/daemon.py +++ b/daemon.py @@ -1117,7 +1117,8 @@ class PubServer(BaseHTTPRequestHandler): return False def _redirect_headers(self, redirect: str, cookie: str, - calling_domain: str) -> None: + calling_domain: str, + code: int = 303) -> None: if '://' not in redirect: if calling_domain.endswith('.onion') and self.server.onion_domain: redirect = 'http://' + self.server.onion_domain + redirect @@ -1130,7 +1131,10 @@ class PubServer(BaseHTTPRequestHandler): print('WARN: redirect was not an absolute url, changed to ' + redirect) - self.send_response(303) + self.send_response(code) + + if code != 303: + print('Redirect headers: ' + str(code)) if cookie: cookie_str = cookie.replace('SET:', '').strip() @@ -1743,7 +1747,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.domain_full) if protocol_url: self._redirect_headers(protocol_url, cookie, - calling_domain) + calling_domain, 308) else: self._404() return True diff --git a/webfinger.py b/webfinger.py index bca2c30cc..b9686d387 100644 --- a/webfinger.py +++ b/webfinger.py @@ -255,7 +255,6 @@ def webfinger_meta(http_prefix: str, domain_full: str) -> str: def wellknown_protocol_handler(path: str, base_dir: str, http_prefix: str, domain_full: str) -> {}: """See https://fedi-to.github.io/protocol-handler.html - Only return the path, not the full url """ if not path.startswith('/.well-known/protocol-handler?'): return None @@ -282,7 +281,7 @@ def wellknown_protocol_handler(path: str, base_dir: str, domain = domain_full # not an open redirect if domain == domain_full: - return '/users/' + nickname + return http_prefix + '://' + domain_full + '/users/' + nickname return None