Block incoming items at the earliest stage, before anything is written to file

master
Bob Mottram 2019-07-14 21:12:05 +01:00
parent 645f45cfcb
commit 7b8f88fd1b
2 changed files with 11 additions and 1 deletions

View File

@ -46,7 +46,7 @@ def isBlocked(baseDir: str,nickname: str,domain: str, \
"""Is the given nickname blocked?
"""
blockingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
blockHandle=blockNickName+'@'+blockDomain
blockHandle=blockNickname+'@'+blockDomain
if os.path.isfile(blockingFilename):
if blockHandle in open(blockingFilename).read():
return True

View File

@ -36,6 +36,7 @@ from capabilities import CapablePost
from capabilities import capabilitiesReceiveUpdate
from like import updateLikesCollection
from like import undoLikesCollectionEntry
from blocking import isBlocked
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
if not personUrl:
@ -117,6 +118,15 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
"""
if ':' in domain:
domain=domain.split(':')[0]
# block at the ealiest stage possible, which means the data
# isn't written to file
if postJsonObject.get('actor'):
postNickname=getNicknameFromActor(postJsonObject['actor'])
postDomain,postPort=getDomainFromActor(postJsonObject['actor'])
if isBlocked(baseDir,nickname,domain,postNickname,postDomain):
return None
if postJsonObject.get('id'):
postId=postJsonObject['id'].replace('/activity','')
else: