Skip to content

fix(formats): validate App Store metadata write paths - #23215

Open
nijel wants to merge 3 commits into
mainfrom
review/oss-next-rnter5zn
Open

nijel wants to merge 3 commits into
mainfrom
review/oss-next-rnter5zn

Conversation

@nijel

@nijel nijel commented Nov 29, 2026

Copy link
Copy Markdown
Member

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.

@nijel nijel added this to the 2026.12 milestone Nov 29, 2026
@nijel nijel self-assigned this Nov 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T19:04:57.078800Z 699c76c New commits
🔒 Security Review ✅ Completed 2026-11-29T18:34:24.228578Z 59dbcf0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread weblate/formats/tests/test_txt.py Resolved
@nijel
nijel force-pushed the review/oss-next-rnter5zn branch from 59dbcf0 to 668e26d Compare November 29, 2026 18:54

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="weblate/formats/tests/test_txt.py">

<violation number="1" location="weblate/formats/tests/test_txt.py:69">
P2: This change drops the save() check that an existing target file keeps its contents. Only delete_unit now runs with an existing file, and save() is only tested when the file is absent. Keep the existing-file save case, for example by running save() under the same `exists` loop.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

(base / "changelogs").symlink_to(outside, target_is_directory=True)
target = outside / "title.txt"
unit = TextItem("changelogs/title.txt", 1, "")
for exists in (True, False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This change drops the save() check that an existing target file keeps its contents. Only delete_unit now runs with an existing file, and save() is only tested when the file is absent. Keep the existing-file save case, for example by running save() under the same exists loop.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At weblate/formats/tests/test_txt.py, line 69:

<comment>This change drops the save() check that an existing target file keeps its contents. Only delete_unit now runs with an existing file, and save() is only tested when the file is absent. Keep the existing-file save case, for example by running save() under the same `exists` loop.</comment>

<file context>
@@ -65,14 +65,16 @@ class AppStoreWritePathTest(SimpleTestCase):
-            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:
</file context>

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.
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.
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.
@nijel
nijel force-pushed the review/oss-next-rnter5zn branch from 668e26d to 699c76c Compare November 29, 2026 19:03
@nijel
nijel enabled auto-merge (squash) November 29, 2026 20:44
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
15727 3 15724 1053
View the top 3 failed test(s) by shortest run time
weblate.utils.tests.test_files.FilesTestCase::test_resolve_path_walks_missing_suffix_once
Stack Traces | 0.002s run time
self = <weblate.utils.tests.test_files.FilesTestCase testMethod=test_resolve_path_walks_missing_suffix_once>

    def test_resolve_path_walks_missing_suffix_once(self) -> None:
        with tempfile.TemporaryDirectory() as tempdir:
            path = os.path.join(tempdir, "missing", *("nested" for _ in range(200)))
            with patch("weblate.utils.files.os.lstat", wraps=os.lstat) as lstat:
>               self.assertEqual(resolve_path(path), Path(path))
E               AssertionError: PosixPath('.../folders/q2/p1t6rgxj5fj32g1dc7[1431 chars]ted') != PosixPath('.../folders/q2/p1t6rgxj5fj32g1dc7dmd49r00[1423 chars]ted')

.../utils/tests/test_files.py:453: AssertionError
weblate.utils.tests.test_files.FilesTestCase::test_is_path_within_directory_rejects_unresolvable_symlink
Stack Traces | 0.005s run time
self = <weblate.utils.tests.test_files.FilesTestCase testMethod=test_is_path_within_directory_rejects_unresolvable_symlink>

    def test_is_path_within_directory_rejects_unresolvable_symlink(self) -> None:
        with tempfile.TemporaryDirectory() as tempdir:
>           repo_path, filename = self.create_unresolvable_symlink(tempdir)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../utils/tests/test_files.py:415: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tempdir = '.../p1t6rgxj5fj32g1dc7dmd49r0000gn/T/tmpyhzb9cg5'

    @staticmethod
    def create_unresolvable_symlink(tempdir: str) -> tuple[str, str]:
        """Create a symlink escaping the repository stored beyond PATH_MAX."""
        repo_path = os.path.join(tempdir, "repo")
        outside_path = os.path.join(tempdir, "outside")
        os.makedirs(repo_path)
        os.makedirs(outside_path)
        Path(outside_path, "secrets.po").write_text("test", encoding="utf-8")
        # Deep enough to exceed PATH_MAX regardless of the temporary directory
        parts = ["d" * 238] * 17
        fd = os.open(repo_path, os.O_RDONLY)
        try:
            for index, part in enumerate(parts):
                os.mkdir(part, dir_fd=fd)
                child = os.open(part, os.O_RDONLY, dir_fd=fd)
                os.close(fd)
                fd = child
                if index == 7:
                    # Keep each symlink target below filesystem length limits.
>                   os.symlink("/".join(parts[8:]), "next", dir_fd=fd)
E                   OSError: [Errno 63] File name too long: '.../dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' -> 'next'

.../utils/tests/test_files.py:403: OSError
weblate.utils.tests.test_files.FilesTestCase::test_resolve_path
Stack Traces | 0.036s run time
self = <weblate.utils.tests.test_files.FilesTestCase testMethod=test_resolve_path>

    def test_resolve_path(self) -> None:
        for resolve in (resolve_path, _realpath_allow_missing):
            with (
                self.subTest(resolve=resolve.__name__),
                tempfile.TemporaryDirectory() as tempdir,
            ):
>               repo_path, filename = self.create_unresolvable_symlink(tempdir)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../utils/tests/test_files.py:426: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tempdir = '.../p1t6rgxj5fj32g1dc7dmd49r0000gn/T/tmp6ztrd8i3'

    @staticmethod
    def create_unresolvable_symlink(tempdir: str) -> tuple[str, str]:
        """Create a symlink escaping the repository stored beyond PATH_MAX."""
        repo_path = os.path.join(tempdir, "repo")
        outside_path = os.path.join(tempdir, "outside")
        os.makedirs(repo_path)
        os.makedirs(outside_path)
        Path(outside_path, "secrets.po").write_text("test", encoding="utf-8")
        # Deep enough to exceed PATH_MAX regardless of the temporary directory
        parts = ["d" * 238] * 17
        fd = os.open(repo_path, os.O_RDONLY)
        try:
            for index, part in enumerate(parts):
                os.mkdir(part, dir_fd=fd)
                child = os.open(part, os.O_RDONLY, dir_fd=fd)
                os.close(fd)
                fd = child
                if index == 7:
                    # Keep each symlink target below filesystem length limits.
>                   os.symlink("/".join(parts[8:]), "next", dir_fd=fd)
E                   OSError: [Errno 63] File name too long: '.../dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' -> 'next'

.../utils/tests/test_files.py:403: OSError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant