From 4b8376151f63ab910efe875f31ba74bf37d350fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Sun, 29 Nov 2026 19:28:35 +0100 Subject: [PATCH 1/3] fix(formats): validate App Store metadata write paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validate each constructed metadata filename before atomic replacement or unlink, including files absent when the format was loaded. Cover both write and deletion through a symlinked directory. Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-RNTER5ZN. --- docs/changes.rst | 1 + weblate/formats/tests/test_txt.py | 56 ++++++++++++++++++++++++++++++- weblate/formats/txt.py | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index dba343ba6140..d5e96dd7c276 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -109,6 +109,7 @@ Weblate 2026.12 * Kept the repository locked while the :ref:`addon-weblate.generate.generate` add-on writes files during installation. * Escaped template syntax in notification settings help built from project and component names. +* Validated App Store metadata destinations before saving or deleting translation files through symlinked directories. * Warn before and after restoring a :ref:`project backup ` when a public-only billing plan makes the project public. * Enforced GitHub App repository and push settings when restoring a :ref:`projectbackup`. diff --git a/weblate/formats/tests/test_txt.py b/weblate/formats/tests/test_txt.py index 6daceb7c9e47..5858ba80980c 100644 --- a/weblate/formats/tests/test_txt.py +++ b/weblate/formats/tests/test_txt.py @@ -8,19 +8,73 @@ import os.path from pathlib import Path +from tempfile import TemporaryDirectory from typing import IO from unittest.mock import Mock, patch from django.core.exceptions import ValidationError +from django.test import SimpleTestCase from weblate.formats.tests.test_formats import BaseFormatTest -from weblate.formats.txt import AppStoreFormat, MultiparserError +from weblate.formats.txt import AppStoreFormat, MultiparserError, TextItem from weblate.lang.models import Language from weblate.trans.tests.utils import get_test_file APPSTORE_FILE = get_test_file("short_description.txt") +class AppStoreWritePathTest(SimpleTestCase): + def test_save_rejects_symlinked_destination_directory(self) -> None: + with TemporaryDirectory() as directory: + root = Path(directory) + base = root / "metadata" + outside = root / "outside" + base.mkdir() + outside.mkdir() + (base / "changelogs").symlink_to(outside, target_is_directory=True) + + def validate(filename: str) -> str: + if not Path(filename).resolve().is_relative_to(base.resolve()): + msg = "Invalid symbolic link in a repository." + raise ValidationError(msg) + return filename + + store = AppStoreFormat(str(base), file_validator=validate) + unit = TextItem("changelogs/title.txt", 1, "attacker") + unit.needs_save = True + store.store.units.append(unit) + + with self.assertRaises(ValidationError): + store.save() + self.assertFalse((outside / "title.txt").exists()) + + def test_delete_rejects_symlinked_destination_directory(self) -> None: + with TemporaryDirectory() as directory: + root = Path(directory) + base = root / "metadata" + outside = root / "outside" + base.mkdir() + outside.mkdir() + + def validate(filename: str) -> str: + if not Path(filename).resolve().is_relative_to(base.resolve()): + msg = "Invalid symbolic link in a repository." + raise ValidationError(msg) + return filename + + store = AppStoreFormat(str(base), file_validator=validate) + (base / "changelogs").symlink_to(outside, target_is_directory=True) + target = outside / "title.txt" + target.write_text("keep", encoding="utf-8") + unit = TextItem("changelogs/title.txt", 1, "") + unit.needs_save = True + store.store.units.append(unit) + + with self.assertRaises(ValidationError): + store.save() + self.assertEqual(target.read_text(encoding="utf-8"), "keep") + + class AppStoreFormatTest(BaseFormatTest): format_class = AppStoreFormat FILE = APPSTORE_FILE diff --git a/weblate/formats/txt.py b/weblate/formats/txt.py index ebdeb6a777f8..05ce2c745700 100644 --- a/weblate/formats/txt.py +++ b/weblate/formats/txt.py @@ -143,7 +143,7 @@ def load_parser(self): return result def get_filename(self, name): - return os.path.join(self.base, name) + return self.file_validator(os.path.join(self.base, name)) class AppStoreParser(MultiParser): From dd8197af4535c42b9dac124507041acc7170cb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Sun, 29 Nov 2026 19:50:04 +0100 Subject: [PATCH 2/3] test(formats): cover App Store metadata deletion path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exercise the delete method with both present and absent files through a symlinked directory, and place the security changelog entry below the shared insertion point. Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-RNTER5ZN. --- docs/changes.rst | 2 +- weblate/formats/tests/test_txt.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index d5e96dd7c276..9a7eb8ebf7da 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -109,7 +109,6 @@ Weblate 2026.12 * Kept the repository locked while the :ref:`addon-weblate.generate.generate` add-on writes files during installation. * Escaped template syntax in notification settings help built from project and component names. -* Validated App Store metadata destinations before saving or deleting translation files through symlinked directories. * Warn before and after restoring a :ref:`project backup ` when a public-only billing plan makes the project public. * Enforced GitHub App repository and push settings when restoring a :ref:`projectbackup`. @@ -123,6 +122,7 @@ Weblate 2026.12 * Removed internal filesystem paths and raw command output from gettext and script :ref:`add-on alerts `. * Redacted remote source URLs from :ref:`JavaScript localization CDN ` alerts and activity logs, including existing records. * Applied the destination project’s :ref:`access controls ` to component history after a move, and linked new category rename and move events to their category. +* Validated App Store metadata destinations before saving or deleting translation files through symlinked directories. * Required project management permission to change a component URL through the API and prevented :ref:`case-insensitive slug conflicts ` from blocking repository cleanup. * Required the site-wide ``language.add`` permission to :http:post:`create a language through the REST API `. diff --git a/weblate/formats/tests/test_txt.py b/weblate/formats/tests/test_txt.py index 5858ba80980c..fddf1d17f980 100644 --- a/weblate/formats/tests/test_txt.py +++ b/weblate/formats/tests/test_txt.py @@ -65,14 +65,16 @@ def validate(filename: str) -> str: store = AppStoreFormat(str(base), file_validator=validate) (base / "changelogs").symlink_to(outside, target_is_directory=True) target = outside / "title.txt" - target.write_text("keep", encoding="utf-8") unit = TextItem("changelogs/title.txt", 1, "") - unit.needs_save = True - store.store.units.append(unit) - - with self.assertRaises(ValidationError): - store.save() - self.assertEqual(target.read_text(encoding="utf-8"), "keep") + for exists in (True, False): + with self.subTest(exists=exists): + if exists: + target.write_text("keep", encoding="utf-8") + with self.assertRaises(ValidationError): + store.delete_unit(unit) + if exists: + self.assertEqual(target.read_text(encoding="utf-8"), "keep") + target.unlink() class AppStoreFormatTest(BaseFormatTest): From 699c76cad181e4a48678f8f198ed68dc36db8168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Sun, 29 Nov 2026 20:03:12 +0100 Subject: [PATCH 3/3] test(formats): preserve existing metadata save coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verify an unsafe App Store save leaves a pre-existing external target unchanged as well as rejecting a missing target. Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-RNTER5ZN. --- weblate/formats/tests/test_txt.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/weblate/formats/tests/test_txt.py b/weblate/formats/tests/test_txt.py index fddf1d17f980..4c76964ddf72 100644 --- a/weblate/formats/tests/test_txt.py +++ b/weblate/formats/tests/test_txt.py @@ -46,7 +46,13 @@ def validate(filename: str) -> str: with self.assertRaises(ValidationError): store.save() - self.assertFalse((outside / "title.txt").exists()) + target = outside / "title.txt" + self.assertFalse(target.exists()) + + target.write_text("keep", encoding="utf-8") + with self.assertRaises(ValidationError): + store.save() + self.assertEqual(target.read_text(encoding="utf-8"), "keep") def test_delete_rejects_symlinked_destination_directory(self) -> None: with TemporaryDirectory() as directory: