Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Weblate 2026.12
* Prevented component creation from writing translation templates outside its repository.
* Applied :setting:`VCS_RESTRICT_PRIVATE` and trusted-host exemptions to :ref:`GitHub App manifest-code and OAuth exchanges <code-hosting-github-app-register>` and API requests, including redirects and pagination URLs.
* Revoked stale OAuth e-mail recovery addresses and reconciled the :ref:`account e-mail <user-profile>` when its last verification is removed.
* Bound password confirmation for adding a sign-in identity to the account and identity it authorized.
* Preserved internationalized recipient domains when sending :ref:`account e-mails <user-profile>` and other notifications.
* Filtered the site-wide changes listings and feeds by workspace visibility, so workspaces the viewer cannot access no longer appear there.
* Restricted :ref:`webhook matching <hooks-target-matching>` to repository owners, preventing generic deliveries from triggering GitHub App updates through linked components.
Expand Down
25 changes: 20 additions & 5 deletions weblate/accounts/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,36 @@ def verify_recent_second_factor(

@partial
def reauthenticate(
strategy, backend, user: User, social, uid, weblate_action, **kwargs
strategy,
backend,
user: User,
social,
uid,
weblate_action,
current_partial,
**kwargs,
):
"""Force authentication when adding new association."""
session = strategy.request.session
if session.pop("reauthenticate_done", False):
return None
confirmed = session.pop("reauthenticate_done", None)
if weblate_action != "activation":
return None
if user and not social and user.has_usable_password():
session["reauthenticate"] = {
association = {
"backend": backend.name,
"backend_verbose": str(get_auth_name(backend.name)),
"uid": uid,
"user_pk": user.pk,
}
if confirmed == {
**association,
"partial_token": session.get(PARTIAL_TOKEN_SESSION_NAME),
}:
return None
session["reauthenticate"] = {
**association,
"partial_token": current_partial.token,
"backend_verbose": str(get_auth_name(backend.name)),
}
return redirect("confirm")
return None

Expand Down
120 changes: 120 additions & 0 deletions weblate/accounts/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from social_core.backends.email import EmailAuth
from social_core.backends.gitea import GiteaOAuth2
from social_core.pipeline.social_auth import social_names
from social_core.utils import PARTIAL_TOKEN_SESSION_NAME
from social_django.models import Code, DjangoStorage, Partial, UserSocialAuth

from weblate.accounts.captcha import solve_altcha
Expand All @@ -48,6 +49,7 @@
from weblate.accounts.pipeline import (
ensure_valid,
handle_invite,
reauthenticate,
store_email,
user_full_name,
)
Expand Down Expand Up @@ -691,6 +693,124 @@ def test_password_change_revokes_pending_addition(self) -> None:
)
self.assert_addition_rejected(url)

def test_password_confirmation_records_association(self) -> None:
association = {
"backend": "email",
"uid": "unused@example.net",
"user_pk": self.user.pk,
"partial_token": "pending-token",
}
session = self.client.session
session["reauthenticate"] = {**association, "backend_verbose": "E-mail"}
session.save()

response = self.client.post(reverse("confirm"), {"password": "secret"})

self.assertRedirects(
response,
reverse("social:complete", args=("email",)),
fetch_redirect_response=False,
)
self.assertEqual(self.client.session["reauthenticate_done"], association)

def test_legacy_password_confirmation_expires(self) -> None:
session = self.client.session
session["reauthenticate"] = {
"backend": "email",
"uid": "unused@example.net",
"user_pk": self.user.pk,
"backend_verbose": "E-mail",
}
session.save()

response = self.client.post(reverse("confirm"), {"password": "secret"})

self.assertRedirects(response, reverse("home"))
self.assertNotIn("reauthenticate", self.client.session)
self.assertNotIn("reauthenticate_done", self.client.session)

def test_signed_out_addition_link_does_not_link_account(self) -> None:
url = self.start_addition()
self.client.logout()

response = self.confirm_registration_url(url)

self.assertRedirects(response, reverse("login"))
self.assertFalse(
VerifiedEmail.objects.filter(email="unused@example.net").exists()
)

def test_password_confirmation_cannot_authorize_other_association(self) -> None:
backend = EmailAuth(WeblateStrategy(DjangoStorage))
session = {
"reauthenticate_done": {
"backend": "email",
"uid": "other-unused@example.net",
"user_pk": self.owner.pk,
"partial_token": "pending-token",
}
}
strategy = SimpleNamespace(request=SimpleNamespace(session=session))
current_partial = SimpleNamespace(token="pending-token")
session[PARTIAL_TOKEN_SESSION_NAME] = "pending-token"

response = reauthenticate.__wrapped__(
strategy,
backend,
self.user,
None,
"unused@example.net",
"activation",
current_partial,
)
self.assertEqual(response.url, reverse("confirm"))
self.assertEqual(session["reauthenticate"]["user_pk"], self.user.pk)
self.assertNotIn("reauthenticate_done", session)

session["reauthenticate_done"] = {
"backend": "email",
"uid": "unused@example.net",
"user_pk": self.user.pk,
"partial_token": "old-token",
}
response = reauthenticate.__wrapped__(
strategy,
backend,
self.user,
None,
"unused@example.net",
"activation",
current_partial,
)
self.assertEqual(response.url, reverse("confirm"))
self.assertNotIn("reauthenticate_done", session)
session["reauthenticate_done"] = {
key: session["reauthenticate"][key]
for key in ("backend", "uid", "user_pk", "partial_token")
}
self.assertIsNone(
reauthenticate.__wrapped__(
strategy,
backend,
self.user,
None,
"unused@example.net",
"activation",
current_partial,
)
)
self.assertNotIn("reauthenticate_done", session)
response = reauthenticate.__wrapped__(
strategy,
backend,
self.user,
None,
"unused@example.net",
"activation",
current_partial,
)
self.assertEqual(response.url, reverse("confirm"))

def test_password_change_revokes_pending_password_confirmation(self) -> None:
url = self.start_addition()
response = self.confirm_registration_url(url)
Expand Down
11 changes: 9 additions & 2 deletions weblate/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@
"active_tab": active_tab,
"form_errors": form_errors,
"userdata_import_form": UserDataImportForm(),
"user_groups": user.groups.select_related(

Check failure on line 651 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

"QuerySet[Group, Group]" has no attribute "order"; maybe "ordered" or "order_by"?
"defining_project", "defining_workspace"
)
.prefetch_related("roles", "projects", "languages", "components")
Expand All @@ -661,8 +661,8 @@
"has_email_auth": "email" in all_backends,
"auditlog": user.auditlog_set.order()[:20],
"saved_searches": user.savedsearch_set.order(),
"totp_keys": user.totpdevice_set.filter(confirmed=True),

Check failure on line 664 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

"User" has no attribute "totpdevice_set"
"webauthn_keys": user.webauthncredential_set.all(),

Check failure on line 665 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

"User" has no attribute "webauthncredential_set"
"recovery_keys_count": StaticToken.objects.filter(
device__user=user
).count(),
Expand Down Expand Up @@ -693,7 +693,7 @@
store_userid(request, remove=True)
request.GET = {"email": request.user.email} # type: ignore[assignment]
AuditLog.objects.create(
request.user, request, "removal-request", **request.GET

Check failure on line 696 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 4 to "create" of "AuditLogManager" has incompatible type "**_ImmutableQueryDict"; expected "User | None"
)
return send_email_confirmation(request)
else:
Expand All @@ -711,7 +711,11 @@
@never_cache
def confirm(request: AuthenticatedHttpRequest):
details = request.session.get("reauthenticate")
if not details:
if not details or not details.get("partial_token"):
# Confirmations started before token binding cannot authorize a
# resumed pipeline. Discard them and require a fresh confirmation.
request.session.pop("reauthenticate", None)
request.session.pop("reauthenticate_done", None)
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
return redirect("home")

if request.method == "POST":
Expand All @@ -720,7 +724,10 @@
)
if confirm_form.is_valid():
request.session.pop("reauthenticate")
request.session["reauthenticate_done"] = True
request.session["reauthenticate_done"] = {
key: details[key]
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
for key in ("backend", "uid", "user_pk", "partial_token")
}
return redirect("social:complete", backend=details["backend"])
else:
confirm_form = PasswordConfirmForm(request)
Expand All @@ -736,7 +743,7 @@
initial = {}
if request.user.is_authenticated:
initial["name"] = request.user.full_name
initial["email"] = request.user.email

Check failure on line 746 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

Incompatible types in assignment (expression has type "str | None", target has type "str")
return initial


Expand Down Expand Up @@ -1420,7 +1427,7 @@
return HttpResponseRedirect(f"{login_url}?{urlencode(login_params)}")
auth_login(self.request, user)
adjust_session_expiry(
request=self.request, user=user, is_login=False, force=True

Check failure on line 1430 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument "request" to "adjust_session_expiry" has incompatible type "HttpRequest"; expected "AuthenticatedHttpRequest"
)
return HttpResponseRedirect(self.get_success_url())

Expand Down Expand Up @@ -2019,7 +2026,7 @@
user or User.objects.get(username=settings.ANONYMOUS_USER_NAME),
)
return (
Suggestion.objects.filter_access(self.request.user)

Check failure on line 2029 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "filter_access" of "SuggestionQuerySet" has incompatible type "User | AnonymousUser"; expected "User"
.filter(
user=user,
unit__translation_id__in=contributor_translations(
Expand Down Expand Up @@ -2628,7 +2635,7 @@
users = users.annotate(**annotations).filter(search_filters).distinct()
elif search:
users = users.search(
search, parser=form.fields["q"].parser, user=self.request.user

Check failure on line 2638 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "parser"
)
elif not unrestricted:
raise Http404
Expand Down Expand Up @@ -2964,7 +2971,7 @@
AuditLog.objects.create(
request.user, request, "twofactor-remove", device=key_name
)
messages.success(request, self.message_remove)

Check failure on line 2974 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "success" has incompatible type "_StrPromise"; expected "str"
elif "name" in data:
obj.name = data["name"]
obj.save(update_fields=["name"])
Expand Down Expand Up @@ -3144,7 +3151,7 @@
device=get_key_name(device),
)
if form.cleaned_data["remove_previous"]:
for old in user.totpdevice_set.filter(confirmed=True).exclude(pk=device.pk):

Check failure on line 3154 in weblate/accounts/views.py

View workflow job for this annotation

GitHub Actions / mypy

"User" has no attribute "totpdevice_set"
key_name = get_key_name(old)
old.delete()
AuditLog.objects.create(
Expand Down
Loading