From 6924ad7e52033365c55d5afacdd916c502cc80cb Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 17:42:00 +0100 Subject: 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. --- webmentions_ssg/url_digest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 webmentions_ssg/url_digest.py (limited to 'webmentions_ssg/url_digest.py') 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 +# +# 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() -- cgit v1.3.1