Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions docs/admin/backup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ The backup can be restored when creating a project (see
:ref:`api` since version 2026.7;

The destination workspace's billing plan determines project access on restore.
When the plan requires public content, restricted components in the backup
are restored as public, including imports initiated by superusers. The import
preview warns about this outcome and lists the affected component paths before
you submit it. The completed import reports each component made public.
When the plan requires public content, non-public projects and restricted
components are restored as public, including imports initiated by superusers.
The import preview warns about this outcome and lists any affected component
paths before you submit it. The completed import reports the change in project
access and each component made public.
Choose a workspace whose plan permits private content to preserve restrictions.
Restoring without destination billing retains the backup's access settings.
See :ref:`workspace-project-creation` for the rules when moving existing projects.
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Weblate 2026.12

.. rubric:: Security fixes

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

* Enforced GitHub App repository and push settings when restoring a :ref:`projectbackup`.
* Enforced :setting:`AUTH_LOCK_ATTEMPTS` for password and :ref:`two-factor <2fa>` sign-ins even when requests arrive concurrently.
* Protected translation file operations, :ref:`downloads <download>`, and :ref:`JavaScript localization CDN <addon-weblate.cdn.cdnjs>` extraction against races with concurrent repository updates.
Expand Down
15 changes: 10 additions & 5 deletions weblate/templates/trans/project_import_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
<p class="help-block">{{ projectbackup.timestamp|naturaltime }}</p>
</div>

{% if restricted_components %}
{% if non_public_project or restricted_components %}
<div class="alert alert-warning" role="alert">
<p><strong>{% translate "Public access on import" %}</strong></p>
<p>{% translate "If the selected workspace's billing plan requires public content, the project and the following restricted components will be publicly accessible after import:" %}</p>
<ul>
{% for component in restricted_components %}<li>{{ component }}</li>{% endfor %}
</ul>
{% if non_public_project %}
<p>{% translate "If the selected workspace's billing plan requires public content, this project will be publicly accessible after import." %}</p>
{% endif %}
{% if restricted_components %}
<p>{% translate "If the selected workspace's billing plan requires public content, the following restricted components will be publicly accessible after import:" %}</p>
<ul>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WCAG 1.3.1: <ul> contains direct text content. Wrap in <li> or <style>.

<ul> and <ol> must only contain <li>, <script>, <template>, or <style> as direct children.

Details

Screen readers announce list structure ('list with 5 items') based on proper markup. Placing non-<li> elements directly inside <ul> or <ol> breaks this structure. Wrap content in <li> elements, or if you need wrapper divs for styling, apply styles to <li> elements directly and remove the wrapper (e.g., change <ul>``<div>item</div>``</ul> to <ul>``<li>item</li>``</ul>).

{% for component in restricted_components %}<li>{{ component }}</li>{% endfor %}
</ul>
{% endif %}
</div>
{% endif %}

Expand Down
20 changes: 19 additions & 1 deletion weblate/trans/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,8 +2605,26 @@ def get_restricted_components(self) -> list[str]:

def get_restore_warnings(self) -> list[str]:
"""Return user-facing warnings for all changes made during import."""
project_warnings = []
if (
self.public_only_restore
and self.project is not None
and self.project.access_control == Project.ACCESS_PUBLIC
and (original_access := self.data["project"]["access_control"])
!= Project.ACCESS_PUBLIC
):
project_warnings.append(
gettext(
"Project access changed from %(original)s to %(current)s because the target workspace's billing plan requires public content."
)
% {
"original": dict(Project.ACCESS_CHOICES)[original_access],
"current": self.project.get_access_control_display(),
}
)
return (
[
project_warnings
+ [
gettext(
"Component %(component)s was skipped because its linked repository is unavailable."
)
Expand Down
10 changes: 7 additions & 3 deletions weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4350,15 +4350,19 @@ def __init__(
)
else:
del self.fields["skip_duplicates"], self.fields["duplicate_scope"]
has_billing = "weblate.billing" in settings.INSTALLED_APPS
self.helper.layout = Layout(
ContextDiv(
template="trans/project_import_info.html",
context={
"projectbackup": projectbackup,
"non_public_project": (
has_billing
and projectbackup.data["project"]["access_control"]
!= Project.ACCESS_PUBLIC
),
"restricted_components": (
projectbackup.get_restricted_components()
if "weblate.billing" in settings.INSTALLED_APPS
else []
projectbackup.get_restricted_components() if has_billing else []
),
},
),
Expand Down
104 changes: 103 additions & 1 deletion weblate/trans/tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@
backup_fields & editable_fields,
)
# ruff: ignore[private-member-access]
self.assertLessEqual(set(form._meta.fields), backup_fields)

Check failure on line 212 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "set" has incompatible type "Collection[str] | None"; expected "Iterable[str]"

Check failure on line 212 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Access to generic instance variables via class is ambiguous
self.assertLessEqual(backup_fields, schema_fields)

def test_migrate_component_file_format_params_xliff_version_gate(self) -> None:
cases = (

Check failure on line 216 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "cases"
(
"2026.9",
"xliff2",
Expand Down Expand Up @@ -1218,21 +1218,31 @@
for warning in restore.get_restore_warnings()
if "restored as public" in warning
]
project_warnings = [
warning
for warning in restore.get_restore_warnings()
if "Project access changed" in warning
]
if made_public:
self.assertEqual(len(public_warnings), 1)
self.assertIn(self.component.slug, public_warnings[0])
self.assertEqual(len(project_warnings), 1)
self.assertIn("from Private to Public", project_warnings[0])
self.assertEqual(
Client().get(component.get_absolute_url()).status_code, 200
)
else:
self.assertEqual(public_warnings, [])
self.assertEqual(project_warnings, [])
# Reusing the restore must not mutate input flags or retain old warnings.
self.assertIn(self.component.slug, restore.get_restricted_components())

@modify_settings(INSTALLED_APPS={"append": "weblate.billing"})
def test_import_preview_warns_before_exposing_restricted_components(self) -> None:
Project.objects.filter(pk=self.project.pk).update(
use_shared_tm=False, contribute_shared_tm=False
access_control=Project.ACCESS_PUBLIC,
use_shared_tm=False,
contribute_shared_tm=False,
)
Component.objects.filter(pk=self.component.pk).update(restricted=True)
self.project.refresh_from_db()
Expand All @@ -1255,6 +1265,25 @@
self.assertEqual(Project.objects.filter(workspace=billing.workspace).count(), 0)
# The notice remains accurate if a different workspace is selected below it.
self.assertContains(response, "If the selected workspace")
self.assertNotContains(response, "this project will be publicly accessible")

result = import_project_backup(
"Restored public project",
"restored-public-project",
self.user.id,
self.client.session["import_project"],
billing_id=billing.pk,
workspace_id=str(billing.workspace_id),
)
self.assertEqual(
result["warnings"],
[
(
f"Restricted component {self.component.slug} was restored as public "
"because the target workspace's billing plan requires public content."
)
],
)

def test_download_uses_configured_static_storage(self) -> None:
storage = MagicMock()
Expand Down Expand Up @@ -1425,7 +1454,7 @@
yield

def test_restore_rejects_malformed_stored_parameters(self) -> None:
for family, values in (

Check failure on line 1457 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Need type annotation for "values"
("vcs_params", (None, [], "", False)),
("file_format_params", (None, [], "", False)),
):
Expand Down Expand Up @@ -4299,7 +4328,7 @@
for field in ("repo", "push"):
with self.subTest(field=field):
temp_name = self.write_tampered_component_backup(
**{field: ("ssh://example.com/repository\r[alias]\rlog = !true")}

Check failure on line 4331 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "write_tampered_component_backup" of "BackupsTest" has incompatible type "**dict[str, str]"; expected "bool"

Check failure on line 4331 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "write_tampered_component_backup" of "BackupsTest" has incompatible type "**dict[str, str]"; expected "tuple[str, ...]"

Check failure on line 4331 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "write_tampered_component_backup" of "BackupsTest" has incompatible type "**dict[str, str]"; expected "dict[Any, Any] | None"
)

with remove_file_after(temp_name):
Expand Down Expand Up @@ -5529,6 +5558,79 @@
self.assertFalse(Project.objects.filter(slug="import-test").exists())


class BackupVisibilityTest(ReusableViewTestCase):
def _backup_project(self, access_control: int) -> ProjectBackup:
Project.objects.filter(pk=self.project.pk).update(
access_control=access_control,
use_shared_tm=False,
contribute_shared_tm=False,
)
self.project.component_set.update(restricted=False)
self.project.refresh_from_db()
backup = ProjectBackup()
backup.backup_project(self.project)
self.addCleanup(Path(backup.filename).unlink, missing_ok=True)
return backup

@modify_settings(INSTALLED_APPS={"append": "weblate.billing"})
def test_import_warns_before_and_after_making_private_project_public(self) -> None:
backup = self._backup_project(Project.ACCESS_PRIVATE)
billing = create_test_billing(self.user)
billing.plan.change_access_control = False
billing.plan.save(update_fields=["change_access_control"])
self.user.is_superuser = True
self.user.save(update_fields=["is_superuser"])
url = reverse("create-project-import")
with open(backup.filename, "rb") as handle:
response = self.client.post(
url, {"zipfile": handle, "workspace": billing.workspace_id}, follow=True
)
self.assertContains(response, "Public access on import")
self.assertContains(
response, "this project will be publicly accessible after import."
)
self.assertNotContains(response, "the following restricted components")
self.assertFalse(Project.objects.filter(workspace=billing.workspace).exists())

with modify_settings(INSTALLED_APPS={"remove": "weblate.billing"}):
self.assertNotContains(self.client.get(url), "Public access on import")

result = import_project_backup(
"Restored private project",
"restored-private-project",
self.user.id,
self.client.session["import_project"],
billing_id=billing.pk,
workspace_id=str(billing.workspace_id),
)
project = Project.objects.get(slug="restored-private-project")
self.assertEqual(project.access_control, Project.ACCESS_PUBLIC)
self.assertEqual(
result,
{
"message": "Project backup import completed with warnings.",
"warnings": [
(
"Project access changed from Private to Public because the target "
"workspace's billing plan requires public content."
)
],
},
)

@modify_settings(INSTALLED_APPS={"append": "weblate.billing"})
def test_import_preview_omits_warning_for_public_backup(self) -> None:
backup = self._backup_project(Project.ACCESS_PUBLIC)
self.user.is_superuser = True
self.user.save(update_fields=["is_superuser"])
with open(backup.filename, "rb") as handle:
response = self.client.post(
reverse("create-project-import"), {"zipfile": handle}, follow=True
)
with remove_file_after(self.client.session["import_project"]):
self.assertNotContains(response, "Public access on import")


class GitHubAppBackupTest(ReusableViewTestCase):
def github_app_backup(self) -> str:
Component.objects.filter(pk=self.component.pk).update(
Expand Down Expand Up @@ -5698,7 +5800,7 @@

def test_backup_omits_git_worktree_state(self) -> None:
repository = self.component.repository
worktree = GitUpdateWorktree(repository)

Check failure on line 5803 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "GitUpdateWorktree" has incompatible type "Repository"; expected "GitRepository"
with repository.lock:
worktree.directory.mkdir(parents=True)
repository.execute(
Expand All @@ -5721,12 +5823,12 @@

def test_backup_rejects_interrupted_git_publication(self) -> None:
repository = self.component.repository
worktree = GitUpdateWorktree(repository)

Check failure on line 5826 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "GitUpdateWorktree" has incompatible type "Repository"; expected "GitRepository"
with repository.lock:
worktree.directory.mkdir(parents=True)
revision = repository.get_last_revision()
worktree.record_publication(
Publication(repository.get_current_branch(), revision)

Check failure on line 5831 in weblate/trans/tests/test_backups.py

View workflow job for this annotation

GitHub Actions / mypy

"Repository" has no attribute "get_current_branch"; maybe "get_remote_branch"?
)
backup = ProjectBackup()
with self.assertRaisesRegex(RepositoryInternalError, "interrupted Git update"):
Expand Down
Loading