Redirect parameter

merge-requests/30/head
Bob Mottram 2023-01-09 22:49:17 +00:00
parent 375550c331
commit bbbe6b21ea
2 changed files with 8 additions and 5 deletions

View File

@ -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

View File

@ -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