From: Roland Häder Date: Mon, 20 Nov 2023 02:10:15 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3a721d5b81fa761654069c2a6c100d0a6690a499;p=fba.git Continued: - more redundant checks against blacklist to avoid bad function invocations --- diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 1434697..e48e08c 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -18,6 +18,7 @@ import logging import bs4 +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -36,6 +37,8 @@ def fetch_blocks(domain: str) -> list: if not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") + elif blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") blocklist = list() block_tag = None diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index 638cf79..9b03517 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -19,6 +19,7 @@ import logging import bs4 +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -71,6 +72,9 @@ def fetch_peers(domain: str, origin: str) -> list: logger.debug("domain='%s',origin='%s' - CALLED!", domain, origin) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + peers = list() # No CSRF by default, you don't have to add network.api_headers by yourself here @@ -121,7 +125,9 @@ def fetch_blocks(domain: str) -> list: logger.debug("domain='%s - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") blocklist = list() @@ -233,6 +239,9 @@ def fetch_instances(domain: str, origin: str) -> list: logger.debug("domain='%s',origin='%s' - CALLED!", domain, origin) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + peers = list() try: diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 85cd5c7..be22e94 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -19,6 +19,7 @@ import validators import bs4 +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -62,7 +63,9 @@ def fetch_blocks_from_about(domain: str) -> dict: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") logger.info("Fetching mastodon blocks from domain='%s'", domain) @@ -147,7 +150,9 @@ def fetch_blocks(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") blocklist = list() diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index 8ec994d..e318cd6 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -17,6 +17,7 @@ import json import logging +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import dicts as dict_helper from fba.helpers import domain as domain_helper @@ -34,6 +35,9 @@ def fetch_peers(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + logger.debug("domain='%s' is misskey, sending API POST request ...", domain) peers = list() offset = 0 @@ -128,7 +132,9 @@ def fetch_blocks(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") # No CSRF by default, you don't have to add network.api_headers by yourself here diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index 773af21..61c9e39 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -16,6 +16,7 @@ import logging +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper @@ -31,6 +32,9 @@ def fetch_peers(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + # Init variables peers = list() headers = tuple() diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index a7c2518..3b58056 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -21,6 +21,7 @@ import bs4 from fba import database from fba import utils +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -54,7 +55,9 @@ def fetch_blocks(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") blockdict = list() @@ -292,7 +295,9 @@ def fetch_blocks_from_about(domain: str) -> dict: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") logger.debug("Fetching mastodon blocks from domain='%s'", domain)