Skip to content

fix(vcs): anchor Mercurial file arguments - #23220

Open
nijel wants to merge 2 commits into
mainfrom
review/oss-next-8n4vzl36
Open

nijel wants to merge 2 commits into
mainfrom
review/oss-next-8n4vzl36

Conversation

@nijel

@nijel nijel commented Nov 29, 2026

Copy link
Copy Markdown
Member

Pass relative repository paths to Mercurial as literal file names in cat, status, commit, and remove operations.

Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-8N4VZL36.

@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-29T18:56:27.026565Z 7411ca9 New commits
🔒 Security Review ✅ Completed 2026-11-29T18:46:08.904964Z 407b8cc 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.

1 issue found across 3 files

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/vcs/mercurial.py">

<violation number="1" location="weblate/vcs/mercurial.py:336">
P2: An empty file name becomes `.`, so `commit(files=[""])` can stage and commit the entire working tree; reject empty paths before joining.</violation>
</file>

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

Turn on auto-fix | Re-trigger cubic

Comment thread weblate/vcs/mercurial.py
@staticmethod
def get_file_argument(path: str) -> str:
"""Anchor a path so Mercurial parses it as a literal file name."""
return os.path.join(os.curdir, path)

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: An empty file name becomes ., so commit(files=[""]) can stage and commit the entire working tree; reject empty paths before joining.

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/vcs/mercurial.py, line 336:

<comment>An empty file name becomes `.`, so `commit(files=[""])` can stage and commit the entire working tree; reject empty paths before joining.</comment>

<file context>
@@ -330,13 +330,18 @@ def merge(
+    @staticmethod
+    def get_file_argument(path: str) -> str:
+        """Anchor a path so Mercurial parses it as a literal file name."""
+        return os.path.join(os.curdir, path)
+
     def needs_commit(self, filenames: list[str] | None = None) -> bool:
</file context>
Suggested change
return os.path.join(os.curdir, path)
if not path:
raise ValueError("File path must not be empty")
return os.path.join(os.curdir, path)

Pass relative repository paths to Mercurial as literal file names in cat, status, commit, and remove operations.

Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-8N4VZL36.
Avoid converting an empty filename into the current directory before add or commit, and place the security changelog entry below the shared insertion point.

Discovered by Anthropic’s OSS Scanner, as vulnerability ANT-2026-8N4VZL36.
@nijel
nijel force-pushed the review/oss-next-8n4vzl36 branch from 407b8cc to 7411ca9 Compare November 29, 2026 18:55
@nijel
nijel enabled auto-merge (squash) November 29, 2026 20:43
@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.004s 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.008s 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/tmpey4h78gv'

    @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.043s 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/tmpechj70zz'

    @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