]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 26 Aug 2023 21:03:37 +0000 (23:03 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 26 Aug 2023 21:03:37 +0000 (23:03 +0200)
- warn about invalid SHA256 domain digests (aka. hashes)
- some mastodon instances maybe not include them at all?

fba/networks/mastodon.py

index c1eb6b779d59a696438effb05c5a2a461aaa99b4..4eebffe0df787eb742189d0ab6056e6146cf6955 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 import logging
+import validators
 
 import bs4
 
@@ -202,6 +203,9 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
                 elif block["severity"] in ["accept", "accepted"]:
                     logger.debug("block[domain]='%s' has unwanted severity level '%s' - SKIPPED!", block["domain"], block["severity"])
                     continue
+                elif "digest" in block and validators.hashes.sha256(block["digest"]):
+                    logger.warning("block[domain]='%s' has invalid block[digest]='%s' - SKIPPED!", block["domain"], block["digest"])
+                    continue
 
                 reason = tidyup.reason(block["comment"]) if "comment" in block and block["comment"] is not None and block["comment"] != "" else None
 
@@ -209,7 +213,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
                 blocklist.append({
                     "blocker"    : domain,
                     "blocked"    : block["domain"],
-                    "hash"       : block["digest"],
+                    "hash"       : block["digest"] if "digest" in block else None,
                     "reason"     : reason,
                     "block_level": blocks.alias_block_level(block["severity"]),
                 })