From 28d30ed49757b6c5136593f85c1e4876f56fd126 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 9 Sep 2019 17:02:14 +0100 Subject: [PATCH] Check for blocked domains being announced --- blocking.py | 11 +++++++++++ inbox.py | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/blocking.py b/blocking.py index e9440e43..fa6073ae 100644 --- a/blocking.py +++ b/blocking.py @@ -113,6 +113,17 @@ def isBlockedHashtag(baseDir: str,hashtag: str) -> bool: return True return False +def isBlockedDomain(baseDir: str,domain: str) -> bool: + """Is the given domain blocked? + """ + if isEvil(domain): + return True + globalBlockingFilename=baseDir+'/accounts/blocking.txt' + if os.path.isfile(globalBlockingFilename): + if '*@'+domain in open(globalBlockingFilename).read(): + return True + return False + def isBlocked(baseDir: str,nickname: str,domain: str, \ blockNickname: str,blockDomain: str) -> bool: """Is the given nickname blocked? diff --git a/inbox.py b/inbox.py index 2b4fe073..c645da14 100644 --- a/inbox.py +++ b/inbox.py @@ -42,6 +42,7 @@ from blocking import isBlocked from filters import isFiltered from announce import updateAnnounceCollection from httpsig import messageContentDigest +from blocking import isBlockedDomain def validInbox(baseDir: str,nickname: str,domain: str) -> bool: """Checks whether files were correctly saved to the inbox @@ -918,6 +919,13 @@ def receiveAnnounce(session,handle: str,baseDir: str, \ if debug: print('DEBUG: "statuses" missing from object in '+messageJson['type']) return False + objectDomain=messageJson['object'].replace('https://','').replace('http://','').replace('dat://','') + if '/' in objectDomain: + objectDomain=objectDomain.split('/')[0] + if isBlockedDomain(baseDir,objectDomain): + if debug: + print('DEBUG: announced domain is blocked') + return False if not os.path.isdir(baseDir+'/accounts/'+handle): print('DEBUG: unknown recipient of announce - '+handle) # is this post in the outbox of the person?