aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/forms.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-15 20:42:20 +0100
committerDennis Fink2026-11-15 20:42:20 +0100
commit509d93b2976e353d29441a7a7b7e78ca466dc4fd (patch)
tree753e637aefabd4293f808addbf9c310eaf0aa552 /webmentions_ssg/forms.py
parentc74feda222745ab7cca8993df83d9ea5f9d07e5b (diff)
downloadwebmentions-ssg-509d93b2976e353d29441a7a7b7e78ca466dc4fd.tar.gz
webmentions-ssg-509d93b2976e353d29441a7a7b7e78ca466dc4fd.zip
refactor(core)!: standardize application terminology
Rename configuration keys, task helpers, forms, network utilities, and view endpoints to make their responsibilities and domains more explicit. Align source-management routes and templates with the new terminology and rename the target-matching module and related task abstractions consistently. BREAKING CHANGE: configuration keys have been renamed and sent-source routes move from `/sent` to `/sources`, with corresponding blueprint endpoint changes.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/forms.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/webmentions_ssg/forms.py b/webmentions_ssg/forms.py
index e3dcdc0..c8ad0ba 100644
--- a/webmentions_ssg/forms.py
+++ b/webmentions_ssg/forms.py
@@ -13,11 +13,11 @@ from wtforms import Field, PasswordField, StringField, SubmitField, ValidationEr
from wtforms.form import BaseForm
from wtforms.validators import InputRequired, StopValidation
-from .net import hostname_of, is_public_address
+from .net import is_public_address, normalized_hostname
from .validation import is_control_character
-class URLMaxBytes:
+class MaxURLBytes:
"""Check the UTF-8 byte length of a submitted URL using the current config."""
def __init__(
@@ -43,7 +43,7 @@ class URLMaxBytes:
)
-class HTTPURL:
+class StrictHTTPURL:
"""Require an HTTP(S) URL that httpx can parse without rewriting whitespace.
httpx automatically percent-encodes some whitespace. Reject it instead of
@@ -75,7 +75,7 @@ class HTTPURL:
)
-class AllowedHostname:
+class AllowedTargetHostname:
"""Validate that a URL uses an allowed hostname.
:param message: Optional validation error message.
@@ -95,8 +95,11 @@ class AllowedHostname:
:param field: Field containing the URL to validate.
:raises ValidationError: If the URL hostname is not configured as allowed.
"""
- hostname = hostname_of(field.data)
- if hostname is not None and hostname in current_app.config["ALLOWED_HOSTNAMES"]:
+ hostname = normalized_hostname(field.data)
+ if (
+ hostname is not None
+ and hostname in current_app.config["ALLOWED_TARGET_HOSTNAMES"]
+ ):
return
raise ValidationError(self.message or field.gettext("Invalid input."))
@@ -105,7 +108,7 @@ class PublicIPLiteral:
"""Reject non-public IP literals without performing DNS in the web worker."""
def __call__(self, form: BaseForm, field: Field) -> None:
- hostname = hostname_of(field.data)
+ hostname = normalized_hostname(field.data)
if hostname is None:
raise ValidationError(field.gettext("Invalid input."))
@@ -126,7 +129,7 @@ class LoginForm(FlaskForm):
submit = SubmitField("Sign In")
-class EndpointForm(FlaskForm):
+class WebmentionSubmissionForm(FlaskForm):
"""Form for receiving a Webmention.
The source must be a public HTTP or HTTPS URL distinct from the target.
@@ -135,11 +138,16 @@ class EndpointForm(FlaskForm):
source = StringField(
"source",
- validators=[InputRequired(), URLMaxBytes(), HTTPURL(), PublicIPLiteral()],
+ validators=[InputRequired(), MaxURLBytes(), StrictHTTPURL(), PublicIPLiteral()],
)
target = StringField(
"target",
- validators=[InputRequired(), URLMaxBytes(), HTTPURL(), AllowedHostname()],
+ validators=[
+ InputRequired(),
+ MaxURLBytes(),
+ StrictHTTPURL(),
+ AllowedTargetHostname(),
+ ],
)
def validate_source(self, field: Field) -> None:
@@ -152,7 +160,7 @@ class EndpointForm(FlaskForm):
raise ValidationError(field.gettext("Field must not be equal to target."))
-class AdminActionForm(FlaskForm):
+class ConfirmActionForm(FlaskForm):
"""Form for confirming an administrative action."""
submit = SubmitField("Confirm")