aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 21:27:28 +0100
committerDennis Fink2026-11-13 21:27:28 +0100
commitb0f3eeb78bcf601982d04f3aa595ab8942de417f (patch)
tree95f9fdd8eb4989b7b026a618ecbb952820584d13
parenta285fdf29e59c3b957247ea9241943c7202e9a28 (diff)
downloadwebmentions-ssg-b0f3eeb78bcf601982d04f3aa595ab8942de417f.tar.gz
webmentions-ssg-b0f3eeb78bcf601982d04f3aa595ab8942de417f.zip
fix(core): reject invalid admin action forms
Centralize administrative form validation so all protected actions return HTTP 400 on invalid submissions instead of allowing the rescan action to fail silently.
Diffstat (limited to '')
-rw-r--r--tests/views/test_admin.py4
-rw-r--r--webmentions_ssg/views/admin.py30
2 files changed, 16 insertions, 18 deletions
diff --git a/tests/views/test_admin.py b/tests/views/test_admin.py
index 1499f64..f166318 100644
--- a/tests/views/test_admin.py
+++ b/tests/views/test_admin.py
@@ -225,11 +225,11 @@ def test_rescan_sent_sources(
response = client.post("/sent/rescan")
- assert response.status_code == 302
- assert response.headers["Location"].endswith("/sent")
+ assert response.status_code == (302 if valid else 400)
form.validate_on_submit.assert_called_once_with()
if valid:
+ assert response.headers["Location"].endswith("/sent")
manual_scan_sources.assert_called_once_with()
else:
manual_scan_sources.assert_not_called()
diff --git a/webmentions_ssg/views/admin.py b/webmentions_ssg/views/admin.py
index 794bcdf..f095de8 100644
--- a/webmentions_ssg/views/admin.py
+++ b/webmentions_ssg/views/admin.py
@@ -21,6 +21,12 @@ from ..tasks.sender import send_webmention
from .blueprint import root_page
+def validate_admin_action() -> None:
+ """Reject invalid administrative action forms with HTTP 400."""
+ if not forms.AdminActionForm().validate_on_submit():
+ abort(400)
+
+
@root_page.route("/received")
@login_required
def received() -> ResponseReturnValue:
@@ -49,10 +55,7 @@ def delete_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue:
:param identifier: Identifier of the Webmention to delete.
:return: Redirect response to the received Webmentions view.
"""
- form = forms.AdminActionForm()
-
- if not form.validate_on_submit():
- abort(400)
+ validate_admin_action()
webmention = db.get_or_404(ReceivedWebmention, identifier)
@@ -76,10 +79,7 @@ def reverify_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue:
:param identifier: Identifier of the Webmention to reverify.
:return: Redirect response to the received Webmentions view.
"""
- form = forms.AdminActionForm()
-
- if not form.validate_on_submit():
- abort(400)
+ validate_admin_action()
webmention = db.get_or_404(ReceivedWebmention, identifier)
@@ -124,10 +124,11 @@ def rescan_sent_sources() -> ResponseReturnValue:
:return: Redirect response to the sent Webmentions view.
"""
- form = forms.AdminActionForm()
- if form.validate_on_submit():
- manual_scan_sources()
- flash("Source rescan queued.", "success")
+ validate_admin_action()
+
+ manual_scan_sources()
+ flash("Source rescan queued.", "success")
+
return redirect(url_for("root.sent"))
@@ -173,10 +174,7 @@ def resend_sent_webmention(
:param webmention_identifier: Identifier of the sent Webmention to resend.
:return: Redirect response to the source details view.
"""
- form = forms.AdminActionForm()
-
- if not form.validate_on_submit():
- abort(400)
+ validate_admin_action()
webmention = db.get_or_404(SentWebmention, webmention_identifier)