From bca995ad54de2b92cc7746f6da27b5f022807d15 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 12 Sep 2021 14:42:18 +0100 Subject: [PATCH] Check POST to i2p domain --- daemon.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/daemon.py b/daemon.py index 5466d2813..15edb731f 100644 --- a/daemon.py +++ b/daemon.py @@ -11634,6 +11634,18 @@ class PubServer(BaseHTTPRequestHandler): refererDomain = refererDomain.split(')')[0] 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): callingDomain = self.server.domainFull @@ -11664,14 +11676,7 @@ class PubServer(BaseHTTPRequestHandler): self._400() return - # get the user agent - 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'] + uaStr = self._getUserAgent() if self._blockedUserAgent(callingDomain, uaStr): self._400() @@ -15556,6 +15561,13 @@ class PubServer(BaseHTTPRequestHandler): print('POST domain blocked: ' + callingDomain) self._400() 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: if callingDomain != self.server.domain and \ callingDomain != self.server.domainFull: @@ -15563,14 +15575,7 @@ class PubServer(BaseHTTPRequestHandler): self._400() return - # get the user agent - 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'] + uaStr = self._getUserAgent() if self._blockedUserAgent(callingDomain, uaStr): self._400()