From 8def6fe89d2d3320aff9165782f7731296725c7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 31 Jul 2023 11:51:56 +0200 Subject: [PATCH] Continued: - prevent blacklisted entries being processed, throw an exception if it happens --- fba/commands.py | 4 ++++ fba/helpers/processing.py | 3 +++ fba/models/instances.py | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index b8866b5..bd2dd22 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1619,9 +1619,13 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: if blocked is not None and blocked != block["blocked"]: logger.debug("blocked='%s' was deobfuscated to blocked='%s'", block["blocked"], blocked) obfuscated = obfuscated - 1 + if blocks.is_instance_blocked(row["domain"], blocked): logger.debug("blocked='%s' is already blocked by domain='%s' - SKIPPED!", blocked, row["domain"]) continue + elif blacklist.is_blacklisted(blocked): + logger.debug("blocked='%s' is blacklisted - SKIPPED!", blocked) + continue block["block_level"] = blocks.alias_block_level(block["block_level"]) diff --git a/fba/helpers/processing.py b/fba/helpers/processing.py index 87c313f..3567292 100644 --- a/fba/helpers/processing.py +++ b/fba/helpers/processing.py @@ -17,6 +17,7 @@ import logging from fba import utils +from fba.helpers import blacklist from fba.helpers import domain as domain_helper from fba.http import federation @@ -82,6 +83,8 @@ def block(blocker: str, blocked: str, reason: str, block_level: str) -> bool: raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter block_level is empty") + elif blacklist.is_blacklisted(blocked): + raise ValueError(f"blocked='{blocked}' is blacklisted but function was invoked") if not blocks.is_instance_blocked(blocker, blocked, block_level): logger.debug("Invoking blocks.add(%s, %s, %s, %s) ...", blocker, blocked, reason, block_level) diff --git a/fba/models/instances.py b/fba/models/instances.py index 2f6f826..18cd7b6 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -123,7 +123,7 @@ def update_data(domain: str): logger.debug("sql_string(%d)='%s'", len(sql_string), sql_string) if sql_string == "": - raise ValueError(f"No fields have been set, but method invoked, domain='{domain}'") + raise ValueError(f"No fields have been set, but function invoked, domain='{domain}'") # Set last_updated to current timestamp fields.append(time.time()) @@ -177,7 +177,7 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str elif origin is not None and not validators.domain(origin.split("/")[0]): raise ValueError(f"Bad origin name='{origin}'") elif blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted, but method invoked") + raise Exception(f"domain='{domain}' is blacklisted, but function invoked") elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (is_registered(domain.split("/")[0]) and domain.find("/c/") > 0): raise Exception(f"domain='{domain}' is a single user") elif domain.find("/tag/") > 0: -- 2.39.5