Check POST to i2p domain

main
Bob Mottram 2021-09-12 14:42:18 +01:00
parent 13d5a46b1b
commit bca995ad54
1 changed files with 21 additions and 16 deletions

View File

@ -11634,6 +11634,18 @@ class PubServer(BaseHTTPRequestHandler):
refererDomain = refererDomain.split(')')[0] refererDomain = refererDomain.split(')')[0]
return refererDomain return refererDomain
def _getUserAgent(self) -> str:
"""Returns the user agent string from the headers
"""
uaStr = None
if self.headers.get('User-Agent'):
uaStr = self.headers['User-Agent']
elif self.headers.get('user-agent'):
uaStr = self.headers['user-agent']
elif self.headers.get('User-agent'):
uaStr = self.headers['User-agent']
return uaStr
def do_GET(self): def do_GET(self):
callingDomain = self.server.domainFull callingDomain = self.server.domainFull
@ -11664,14 +11676,7 @@ class PubServer(BaseHTTPRequestHandler):
self._400() self._400()
return return
# get the user agent uaStr = self._getUserAgent()
uaStr = None
if self.headers.get('User-Agent'):
uaStr = self.headers['User-Agent']
elif self.headers.get('user-agent'):
uaStr = self.headers['user-agent']
elif self.headers.get('User-agent'):
uaStr = self.headers['User-agent']
if self._blockedUserAgent(callingDomain, uaStr): if self._blockedUserAgent(callingDomain, uaStr):
self._400() self._400()
@ -15556,6 +15561,13 @@ class PubServer(BaseHTTPRequestHandler):
print('POST domain blocked: ' + callingDomain) print('POST domain blocked: ' + callingDomain)
self._400() self._400()
return return
elif self.server.i2pDomain:
if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull and \
callingDomain != self.server.i2pDomain:
print('POST domain blocked: ' + callingDomain)
self._400()
return
else: else:
if callingDomain != self.server.domain and \ if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull: callingDomain != self.server.domainFull:
@ -15563,14 +15575,7 @@ class PubServer(BaseHTTPRequestHandler):
self._400() self._400()
return return
# get the user agent uaStr = self._getUserAgent()
uaStr = None
if self.headers.get('User-Agent'):
uaStr = self.headers['User-Agent']
elif self.headers.get('user-agent'):
uaStr = self.headers['user-agent']
elif self.headers.get('User-agent'):
uaStr = self.headers['User-agent']
if self._blockedUserAgent(callingDomain, uaStr): if self._blockedUserAgent(callingDomain, uaStr):
self._400() self._400()