Skip to content

Commit c523736

Browse files
committed
fix(components): scope project permission to path changes
Preserve name-only edits for component maintainers while requiring source and destination project management for storage path moves. Extend the regression to both cases. Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-WL5VZHNT.
1 parent 430d8e0 commit c523736

5 files changed

Lines changed: 61 additions & 18 deletions

File tree

‎docs/changes.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ Weblate 2026.12
107107
* Disabled repository-controlled reStructuredText parser imports during Sphinx extraction and checks.
108108
* Kept the repository locked while the :ref:`addon-weblate.generate.generate` add-on writes files during installation.
109109
* Escaped template syntax in notification settings help built from project and component names.
110-
* Required project management permission on the current project to rename a component or :ref:`move it to another project <component-project>`.
111110

112111
* Warn before and after restoring a :ref:`project backup <projectbackup>` when a public-only billing plan makes the project public.
113112

@@ -122,6 +121,7 @@ Weblate 2026.12
122121
* Removed internal filesystem paths and raw command output from gettext and script :ref:`add-on alerts <alerts>`.
123122
* Redacted remote source URLs from :ref:`JavaScript localization CDN <addon-weblate.cdn.cdnjs>` alerts and activity logs, including existing records.
124123
* Applied the destination project’s :ref:`access controls <access-control>` to component history after a move, and linked new category rename and move events to their category.
124+
* Required project management permission on the current project to change a component path or :ref:`move it to another project <component-project>`.
125125

126126
* Required project management permission to change a component URL through the API and prevented :ref:`case-insensitive slug conflicts <component-slug>` from blocking repository cleanup.
127127
* Required the site-wide ``language.add`` permission to :http:post:`create a language through the REST API </api/languages/>`.

‎weblate/trans/forms.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3698,9 +3698,17 @@ class Meta:
36983698

36993699
def __init__(self, request: AuthenticatedHttpRequest, *args, **kwargs) -> None:
37003700
super().__init__(request, *args, **kwargs)
3701-
self.fields["project"].queryset = request.user.accessible_managed_projects
3701+
self.fields["project"].queryset = Project.objects.filter(
3702+
Q(pk=self.instance.project_id)
3703+
| Q(pk__in=request.user.accessible_managed_projects)
3704+
)
37023705
self.fields["category"].queryset = self.instance.project.category_set.all()
37033706

3707+
def clean_project(self) -> Project:
3708+
# The rename view checks source and destination project permissions
3709+
# after it can distinguish a name change from a storage path change.
3710+
return self.cleaned_data["project"]
3711+
37043712

37053713
class ComponentLinkAddForm(ManagedProjectFormMixin, forms.Form):
37063714
"""Form for sharing a component into a project with an optional category."""

‎weblate/trans/tests/test_manage.py‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,35 @@ def test_component_move_requires_source_project_edit(self) -> None:
961961

962962
url = reverse("rename", kwargs=self.kw_component)
963963
response = self.client.get(self.component.get_absolute_url())
964-
self.assertNotContains(response, f'action="{url}"')
964+
self.assertContains(response, f'action="{url}"')
965+
response = self.client.post(
966+
url,
967+
{
968+
"project": self.project.pk,
969+
"slug": self.component.slug,
970+
"name": "Renamed component",
971+
},
972+
)
973+
self.assertRedirects(response, self.component.get_absolute_url())
974+
self.assertEqual(
975+
Component.objects.get(pk=self.component.pk).name, "Renamed component"
976+
)
977+
965978
response = self.client.post(
966979
url,
967980
{
968981
"project": destination.pk,
969982
"slug": self.component.slug,
970-
"name": self.component.name,
983+
"name": "Renamed component",
984+
},
985+
)
986+
self.assertEqual(response.status_code, 403)
987+
response = self.client.post(
988+
url,
989+
{
990+
"project": self.project.pk,
991+
"slug": "changed",
992+
"name": "Renamed component",
971993
},
972994
)
973995
self.assertEqual(response.status_code, 403)

‎weblate/trans/views/basic.py‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -795,17 +795,13 @@ def show_component(request: AuthenticatedHttpRequest, obj: Component) -> HttpRes
795795
"delete_form": optional_form(
796796
ComponentDeleteForm, user, "component.edit", obj, obj=obj
797797
),
798-
"rename_form": (
799-
optional_form(
800-
ComponentRenameForm,
801-
user,
802-
"component.edit",
803-
obj,
804-
request=request,
805-
instance=obj,
806-
)
807-
if user.has_perm("project.edit", obj.project)
808-
else None
798+
"rename_form": optional_form(
799+
ComponentRenameForm,
800+
user,
801+
"component.edit",
802+
obj,
803+
request=request,
804+
instance=obj,
809805
),
810806
"autoform": optional_form(
811807
AutoForm,

‎weblate/trans/views/settings.py‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ def perform_rename(
495495
raise PermissionDenied
496496

497497
with _locked_for_rename(obj) as locked_obj:
498+
if isinstance(locked_obj, Component):
499+
source_project = locked_obj.project
500+
source_slug = locked_obj.slug
501+
source_category_id = locked_obj.category_id
498502
# Make sure any non-rename related issues are resolved first
499503
try:
500504
locked_obj.full_clean()
@@ -516,7 +520,22 @@ def perform_rename(
516520
return redirect_param(locked_obj, "#organize")
517521

518522
target = form.cleaned_data.get("project")
519-
if target is not None and not request.user.has_perm("project.edit", target):
523+
if isinstance(locked_obj, Component):
524+
path_changed = (
525+
target != source_project
526+
or form.cleaned_data["slug"] != source_slug
527+
or getattr(form.cleaned_data.get("category"), "pk", None)
528+
!= source_category_id
529+
)
530+
if path_changed and not request.user.has_perm(
531+
"project.edit", source_project
532+
):
533+
raise PermissionDenied
534+
if target != source_project and not request.user.has_perm(
535+
"project.edit", target
536+
):
537+
raise PermissionDenied
538+
elif target is not None and not request.user.has_perm("project.edit", target):
520539
raise PermissionDenied
521540

522541
# Invalidate old stats
@@ -536,8 +555,6 @@ def rename(request: AuthenticatedHttpRequest, path):
536555
obj = parse_path(request, path, (Component, Project, Category))
537556
try:
538557
if isinstance(obj, Component):
539-
if not request.user.has_perm("project.edit", obj.project):
540-
raise PermissionDenied
541558
return perform_rename(ComponentRenameForm, request, obj, "component.edit")
542559
if isinstance(obj, Category):
543560
return perform_rename(CategoryRenameForm, request, obj, "project.edit")

0 commit comments

Comments
 (0)