From 2d987e41f9ad112785e3d495d387c27ad98fd098 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 24 Mar 2022 19:36:23 +0000 Subject: [PATCH] Always redirect to an absolute url --- daemon.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index 018dd4a3a..09a074aae 100644 --- a/daemon.py +++ b/daemon.py @@ -811,7 +811,15 @@ class PubServer(BaseHTTPRequestHandler): def _logout_redirect(self, redirect: str, cookie: str, calling_domain: str) -> None: if '://' not in redirect: - print('REDIRECT ERROR: redirect is not an absolute url ' + + if calling_domain.endswith('.onion') and self.server.onion_domain: + redirect = 'http://' + self.server.onion_domain + redirect + elif calling_domain.endswith('.i2p') and self.server.i2p_domain: + redirect = 'http://' + self.server.i2p_domain + redirect + else: + redirect = \ + self.server.http_prefix + '://' + \ + self.server.domain_full + redirect + print('WARN: redirect was not an absolute url, changed to ' + redirect) self.send_response(303) @@ -925,7 +933,15 @@ class PubServer(BaseHTTPRequestHandler): def _redirect_headers(self, redirect: str, cookie: str, calling_domain: str) -> None: if '://' not in redirect: - print('REDIRECT ERROR: redirect is not an absolute url ' + + if calling_domain.endswith('.onion') and self.server.onion_domain: + redirect = 'http://' + self.server.onion_domain + redirect + elif calling_domain.endswith('.i2p') and self.server.i2p_domain: + redirect = 'http://' + self.server.i2p_domain + redirect + else: + redirect = \ + self.server.http_prefix + '://' + \ + self.server.domain_full + redirect + print('WARN: redirect was not an absolute url, changed to ' + redirect) self.send_response(303)