From 336b6c8ea9eec0f73915adae3192566ad843f8d7 Mon Sep 17 00:00:00 2001 From: bashrc Date: Fri, 8 May 2026 13:55:50 +0100 Subject: [PATCH] Block domains before post is saved to the inbox --- daemon_utils.py | 6 +++++- inbox.py | 38 +++++++++++++++++++++++++++++++++++++- posts.py | 8 ++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/daemon_utils.py b/daemon_utils.py index e907c9d01..0e38327d6 100644 --- a/daemon_utils.py +++ b/daemon_utils.py @@ -564,7 +564,11 @@ def update_inbox_queue(self, nickname: str, message_json: {}, self.server.block_federated, self.server.system_language, mitm, - self.server.maxMessageLength) + self.server.maxMessageLength, + self.server.block_military, + self.server.block_government, + self.server.block_bluesky, + self.server.block_nostr) if queue_filename: # add json to the queue if queue_filename not in self.server.inbox_queue: diff --git a/inbox.py b/inbox.py index 54248e47b..0dc8a3f1d 100644 --- a/inbox.py +++ b/inbox.py @@ -87,6 +87,10 @@ from blocking import is_blocked from blocking import is_blocked_nickname from blocking import is_blocked_domain from blocking import broch_modeLapses +from blocking import contains_military_domain +from blocking import contains_government_domain +from blocking import contains_bluesky_domain +from blocking import contains_nostr_domain from filters import is_filtered from httpsig import message_content_digest from posts import outbox_message_create_wrap @@ -451,7 +455,11 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, block_federated: [], system_language: str, mitm: bool, - max_message_bytes: int) -> str: + max_message_bytes: int, + block_military: {}, + block_government: {}, + block_bluesky: {}, + block_nostr: {}) -> str: """Saves the given json to the inbox queue for the person key_id specifies the actor sending the post """ @@ -459,6 +467,34 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, print('REJECT: inbox message too long ' + str(len(message_bytes)) + ' bytes') return None + + # Check that the post does not contain a blocked domain + test_text = str(original_post_json_object) + if nickname in block_military: + if block_military[nickname] is True and \ + contains_military_domain(test_text): + print('BLOCK: ' + nickname + + ' blocked military domain inbox') + return None + if nickname in block_government: + if block_government[nickname] is True and \ + contains_government_domain(test_text): + print('BLOCK: ' + nickname + + ' blocked government domain inbox') + return None + if nickname in block_bluesky: + if block_bluesky[nickname] is True and \ + contains_bluesky_domain(test_text): + print('BLOCK: ' + nickname + + ' blocked bluesky domain inbox') + return None + if nickname in block_nostr: + if block_nostr[nickname] is True and \ + contains_nostr_domain(test_text): + print('BLOCK: ' + nickname + + ' blocked nostr domain inbox') + return None + original_domain = domain domain = remove_domain_port(domain) diff --git a/posts.py b/posts.py index 521a1ffff..5ed7e1dc1 100644 --- a/posts.py +++ b/posts.py @@ -6433,6 +6433,8 @@ def download_announce(session, base_dir: str, http_prefix: str, if nickname in block_military: if block_military[nickname] is True and \ contains_military_domain(announced_json_str): + print('BLOCK: ' + nickname + + ' blocked military domain download announce') _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache, debug) @@ -6440,6 +6442,8 @@ def download_announce(session, base_dir: str, http_prefix: str, if nickname in block_government: if block_government[nickname] is True and \ contains_government_domain(announced_json_str): + print('BLOCK: ' + nickname + + ' blocked government domain download announce') _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache, debug) @@ -6447,6 +6451,8 @@ def download_announce(session, base_dir: str, http_prefix: str, if nickname in block_bluesky: if block_bluesky[nickname] is True and \ contains_bluesky_domain(announced_json_str): + print('BLOCK: ' + nickname + + ' blocked bluesky domain download announce') _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache, debug) @@ -6454,6 +6460,8 @@ def download_announce(session, base_dir: str, http_prefix: str, if nickname in block_nostr: if block_nostr[nickname] is True and \ contains_nostr_domain(announced_json_str): + print('BLOCK: ' + nickname + + ' blocked nostr domain download announce') _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache, debug)