aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/url_digest.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 17:42:00 +0100
committerDennis Fink2026-10-31 17:42:00 +0100
commit6924ad7e52033365c55d5afacdd916c502cc80cb (patch)
tree8a52b8e8fbae7a6bcc85d250cac2436a2c42e748 /webmentions_ssg/url_digest.py
parent3494eab1208dc18478485e02c61e292556502fa6 (diff)
downloadwebmentions-ssg-6924ad7e52033365c55d5afacdd916c502cc80cb.tar.gz
webmentions-ssg-6924ad7e52033365c55d5afacdd916c502cc80cb.zip
feat(receiver): add resource limits and retention
Bound incoming request and URL sizes so untrusted Webmention submissions cannot consume unbounded application or database resources. Purge old failed and deleted received Webmentions on a schedule, and use portable SHA-256 URL fingerprints to preserve uniqueness for long URLs.
Diffstat (limited to 'webmentions_ssg/url_digest.py')
-rw-r--r--webmentions_ssg/url_digest.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/webmentions_ssg/url_digest.py b/webmentions_ssg/url_digest.py
new file mode 100644
index 0000000..256d037
--- /dev/null
+++ b/webmentions_ssg/url_digest.py
@@ -0,0 +1,21 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+"""Portable SHA-256 fingerprints for indexed Webmention URLs."""
+
+import hashlib
+import json
+
+
+def received_url_digest(source: str, target: str) -> str:
+ """Fingerprint an unambiguous, ordered source/target pair."""
+ encoded = json.dumps(
+ [source, target], ensure_ascii=False, separators=(",", ":")
+ ).encode("utf-8")
+ return hashlib.sha256(encoded).hexdigest()
+
+
+def sent_target_digest(target: str) -> str:
+ """Fingerprint an outgoing target (unique within each source ID)."""
+ return hashlib.sha256(target.encode("utf-8")).hexdigest()