Reject posts from bad domains early

main
Bob Mottram 2020-04-16 19:49:16 +01:00
parent f3723d4707
commit ecf886d3ed
1 changed files with 11 additions and 1 deletions

View File

@ -86,6 +86,7 @@ from blocking import removeBlock
from blocking import addGlobalBlock from blocking import addGlobalBlock
from blocking import removeGlobalBlock from blocking import removeGlobalBlock
from blocking import isBlockedHashtag from blocking import isBlockedHashtag
from blocking import isBlockedDomain
from blocking import getDomainBlocklist from blocking import getDomainBlocklist
from config import setConfigParam from config import setConfigParam
from config import getConfigParam from config import getConfigParam
@ -789,9 +790,18 @@ class PubServer(BaseHTTPRequestHandler):
messageBytes: str) -> int: messageBytes: str) -> int:
"""Update the inbox queue """Update the inbox queue
""" """
# check for blocked domains so that they can be rejected early
messageDomain = None
if messageJson.get('actor'):
messageDomain = getDomainFromActor(messageJson['actor'])
if isBlockedDomain(self.server.baseDir, messageDomain):
self._400()
self.server.POSTbusy = False
return 3
# if the inbox queue is full then return a busy code # if the inbox queue is full then return a busy code
if len(self.server.inboxQueue) >= self.server.maxQueueLength: if len(self.server.inboxQueue) >= self.server.maxQueueLength:
if messageJson.get('actor'): if messageDomain:
print('Queue: Inbox queue is full. Incoming post from ' + print('Queue: Inbox queue is full. Incoming post from ' +
messageJson['actor']) messageJson['actor'])
else: else: