From ecf886d3ed591638188888b050bfd78d3e8295de Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 16 Apr 2020 19:49:16 +0100 Subject: [PATCH] Reject posts from bad domains early --- daemon.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index 3263aa3b7..0889ba842 100644 --- a/daemon.py +++ b/daemon.py @@ -86,6 +86,7 @@ from blocking import removeBlock from blocking import addGlobalBlock from blocking import removeGlobalBlock from blocking import isBlockedHashtag +from blocking import isBlockedDomain from blocking import getDomainBlocklist from config import setConfigParam from config import getConfigParam @@ -789,9 +790,18 @@ class PubServer(BaseHTTPRequestHandler): messageBytes: str) -> int: """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 len(self.server.inboxQueue) >= self.server.maxQueueLength: - if messageJson.get('actor'): + if messageDomain: print('Queue: Inbox queue is full. Incoming post from ' + messageJson['actor']) else: