From 726af17729e879696e670438a35cdc326c4b960b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 9 Dec 2023 04:03:46 +0100 Subject: [PATCH] Continued: - check if domain is valid before checking if it is blacklisted, else an exception will raise --- fba/networks/pleroma.py | 4 ++++ fba/utils.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index c637f65..a78ead4 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -17,6 +17,7 @@ import logging import bs4 +import validators from fba import database from fba import utils @@ -132,6 +133,9 @@ def fetch_blocks(domain: str) -> list: if blocked in [None, ""]: logger.warning("blocked='%s' is empty after tidyup.domain(): domain='%s',block_level='%s' - SKIPPED!", blocked, domain, block_level) continue + elif validators.domain(blocked) and blacklist.is_blacklisted(blocked): + logger.debug("blocked='%s' is blacklisted - SKIPPED!") + continue logger.debug("Invoking utils.deobfuscate(%s, %s) ...", blocked, domain) blocked = utils.deobfuscate(blocked, domain) diff --git a/fba/utils.py b/fba/utils.py index f698194..7829723 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -127,7 +127,7 @@ def deobfuscate(domain: str, blocker: str, domain_hash: str = None) -> str: logger.debug("domain='%s',blocker='%s',domain_hash='%s' - CALLED!", domain, blocker, domain_hash) domain_helper.raise_on(blocker) - if blacklist.is_blacklisted(domain): + if validators.domain(domain) and blacklist.is_blacklisted(domain): raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") elif not isinstance(domain_hash, str) and domain_hash is not None: raise ValueError(f"Parameter domain_hash[]='{type(domain_hash)}' is not of type 'str'") -- 2.39.5