]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/blacklist.py
Continued:
[fba.git] / fba / helpers / blacklist.py
index 3961d7d5dd432d66f7b5c93bb36306acfea42840..6d0c6ff2da4a947a13a294b8cc9ef5484fa428e6 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-import validators
+import logging
+
+from fba.helpers import domain as domain_helper
+
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+#logger.setLevel(logging.DEBUG)
 
 # Don't check these, known trolls/flooders/testing/developing
-blacklist = [
-    # Floods federation with fake nodes as "research" project
-    "activitypub-troll.cf",
-    # Similar troll
-    "gab.best",
-    # Similar troll
-    "4chan.icu",
-    # Flooder (?)
-    "social.shrimpcam.pw",
-    # Flooder (?)
-    "mastotroll.netz.org",
-    # Testing/developing installations
-    "ngrok.io",
-    "ngrok-free.app",
-    "misskeytest.chn.moe",
-    # block flooder
-    "everyoneattack.com",
-]
+_blacklist = {
+    "activitypub-troll.cf": "Floods federation with fake nodes as \"research\" project",
+    "activitypub-proxy.cf": "Floods federation with fake nodes as \"research\" project",
+    "misskey-forkbomb.cf" : "Floods federation tables with fake nodes",
+    "gab.best"            : "Floods federation tables with fake nodes",
+    "4chan.icu"           : "Floods federation tables with fake nodes",
+    "social.shrimpcam.pw" : "Floods federation tables with fake nodes",
+    "mastotroll.netz.org" : "Floods federation tables with fake nodes",
+    "lhr.life"            : "Floods federation tables with fake nodes",
+    "localhost.run"       : "Floods federation tables with fake nodes",
+    "loca.lt"             : "Floods federation tables with fake nodes",
+    "grid.tf"             : "Floods federation tables with fake nodes",
+    "gitpod.io"           : "Floods federation tables with fake nodes",
+    "everyoneattack.com"  : "Floods federation tables with fake nodes",
+    "vercel.app"          : "Floods federation tables with fake nodes",
+    "run.app"             : "Floods federation tables with fake nodes",
+    "sutty.nl"            : "Floods federation tables with fake nodes",
+    "mdrqnxtagon.pw"      : "Floods federation tables with fake nodes",
+    "denden.world"        : "Looks like a valid Mastodon instance, but return exactly (!) 5k instances with trash domains",
+    "fnaf.stream"         : "Trolls with over-long sub-domain name(s)",
+    "ngrok.io"            : "Testing/developing instances shouldn't be part of public instances",
+    "ngrok.app"           : "Testing/developing instances shouldn't be part of public instances",
+    "ngrok-free.app"      : "Testing/developing instances shouldn't be part of public instances",
+    "misskeytest.chn.moe" : "Testing/developing instances shouldn't be part of public instances",
+    "netlify.app"         : "Testing/developing instances shouldn't be part of public instances",
+    "ignorelist.com"      : "Testing/developing instances shouldn't be part of public instances",
+    "app.github.dev"      : "Testing/developing instances shouldn't be part of public instances",
+    "tunnel.silicon.moe"  : "Testing/developing instances shouldn't be part of public instances",
+    "hexbear.net"         : "Is a Lemmy instance with malicious JavaScript code (shell commands)",
+    "mastodon.n41.lat"    : "Somehow this instance repeatedly causes an OOM here",
+    "fb.me"               : "Facebook websites are never Fediverse instances",
+    "osl.academy"         : "Parked domain, no fediverse instance",
+    "icolectiva.org"      : "Parked domain, no fediverse instance",
+    "blombus.com"         : "Parked domain, no fediverse instance",
+    "eliotberriot.com"    : "Parked domain, no fediverse instance",
+    "fsam.one"            : "Parked domain, no fediverse instance",
+    "doot.tv"             : "Parked domain, no fediverse instance",
+    "snet.blog"           : "Parked domain, no fediverse instance",
+    "horserock.xyz"       : "Parked domain, no fediverse instance",
+    "free-pic.org"        : "Parked domain, no fediverse instance",
+    "co-mastdn.ga"        : "Parked domain, no fediverse instance",
+    "chocoflan.net"       : "Parked domain, no fediverse instance",
+    "qwest.net"           : "Dynamic IP address hosts should not be used for fediverse instances",
+}
 
 def is_blacklisted(domain: str) -> bool:
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-    elif domain.lower() != domain:
-        raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
-    elif not validators.domain(domain.split("/")[0]):
-        raise ValueError(f"domain='{domain}' is not a valid domain")
-    elif domain.endswith(".arpa"):
-        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
-    elif domain.endswith(".tld"):
-        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
+    logger.debug("domain='%s' - CALLED!", domain)
+    domain_helper.raise_on(domain)
 
     blacklisted = False
-    for peer in blacklist:
-        # DEBUG: print(f"DEBUG: Checking peer='{peer}' ...")
-        if peer in domain:
-            # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted.")
+    logger.debug("Checking %d blacklist entries ...", len(_blacklist))
+    for blocked in _blacklist:
+        logger.debug("Checking blocked='%s' ...", blocked)
+        if blocked in domain:
+            logger.debug("domain='%s' is blacklisted.", domain)
             blacklisted = True
+            break
 
-    # DEBUG: print(f"DEBUG: blacklisted='{blacklisted}' - EXIT!")
+    logger.debug("blacklisted='%s' - EXIT!", blacklisted)
     return blacklisted
+
+def get_all() -> dict:
+    logger.debug("_blacklist()=%d - CALLED!", len(_blacklist))
+    return _blacklist