Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-01-30 22:32:58 +00:00
commit 513002f913
1 changed files with 20 additions and 15 deletions

View File

@ -1134,6 +1134,7 @@ class PubServer(BaseHTTPRequestHandler):
show_node_info_accounts) show_node_info_accounts)
def _nodeinfo(self, ua_str: str, calling_domain: str, def _nodeinfo(self, ua_str: str, calling_domain: str,
referer_domain: str,
httpPrefix: str, calling_site_timeout: int, httpPrefix: str, calling_site_timeout: int,
debug: bool) -> bool: debug: bool) -> bool:
if self.path.startswith('/nodeinfo/1.0'): if self.path.startswith('/nodeinfo/1.0'):
@ -1141,7 +1142,11 @@ class PubServer(BaseHTTPRequestHandler):
return True return True
if not self.path.startswith('/nodeinfo/2.0'): if not self.path.startswith('/nodeinfo/2.0'):
return False return False
if calling_domain == self.server.domain_full: if not referer_domain:
if not debug and not self.server.unit_test:
self._400()
return True
if referer_domain == self.server.domain_full:
self._400() self._400()
return True return True
if self.server.nodeinfo_is_active: if self.server.nodeinfo_is_active:
@ -1150,27 +1155,27 @@ class PubServer(BaseHTTPRequestHandler):
return True return True
self.server.nodeinfo_is_active = True self.server.nodeinfo_is_active = True
# is this a real website making the call ? # is this a real website making the call ?
if not debug and not self.server.unit_test: if not debug and not self.server.unit_test and referer_domain:
# Does calling_domain look like a domain? # Does calling_domain look like a domain?
if ' ' in calling_domain or \ if ' ' in referer_domain or \
';' in calling_domain or \ ';' in referer_domain or \
'.' not in calling_domain: '.' not in referer_domain:
print('nodeinfo calling domain does not look like a domain ' + print('nodeinfo referer domain does not look like a domain ' +
calling_domain) referer_domain)
self._400() self._400()
self.server.nodeinfo_is_active = False self.server.nodeinfo_is_active = False
return True return True
if not self.server.allow_local_network_access: if not self.server.allow_local_network_access:
if local_network_host(calling_domain): if local_network_host(referer_domain):
print('nodeinfo calling domain is from the ' + print('nodeinfo referer domain is from the ' +
'local network ' + calling_domain) 'local network ' + referer_domain)
self._400() self._400()
self.server.nodeinfo_is_active = False self.server.nodeinfo_is_active = False
return True return True
if not site_is_active(httpPrefix + '://' + calling_domain, if not site_is_active(httpPrefix + '://' + referer_domain,
calling_site_timeout): calling_site_timeout):
print('nodeinfo calling domain is not active ' + print('nodeinfo referer domain is not active ' +
calling_domain) referer_domain)
self._400() self._400()
self.server.nodeinfo_is_active = False self.server.nodeinfo_is_active = False
return True return True
@ -1215,7 +1220,7 @@ class PubServer(BaseHTTPRequestHandler):
self._set_headers('application/ld+json', msglen, self._set_headers('application/ld+json', msglen,
None, calling_domain, True) None, calling_domain, True)
self._write(msg) self._write(msg)
print('nodeinfo sent to ' + calling_domain) print('nodeinfo sent to ' + referer_domain)
self.server.nodeinfo_is_active = False self.server.nodeinfo_is_active = False
return True return True
self._404() self._404()
@ -13549,7 +13554,7 @@ class PubServer(BaseHTTPRequestHandler):
# Since fediverse crawlers are quite active, # Since fediverse crawlers are quite active,
# make returning info to them high priority # make returning info to them high priority
# get nodeinfo endpoint # get nodeinfo endpoint
if self._nodeinfo(ua_str, calling_domain, if self._nodeinfo(ua_str, calling_domain, referer_domain,
self.server.http_prefix, 5, self.server.debug): self.server.http_prefix, 5, self.server.debug):
return return