Check for blocked domains being announced

master
Bob Mottram 2019-09-09 17:02:14 +01:00
parent a90039b57a
commit 28d30ed497
2 changed files with 19 additions and 0 deletions

View File

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

View File

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