Repository navigation
fix(cmd): Git.polish_url mein remote URLs ko bina badle rakhein - #2370
Closed
Keerthana-64 wants to merge 1 commit into
Closed
Keerthana-64 wants to merge 1 commit into
Keerthana-64 wants to merge 1 commit into
Conversation
`Git.polish_url` replaced every backslash with `/` outside Cygwin so that Windows paths stored in configuration use forward slashes. It runs on every clone URL in `Repo._clone`, which covers `Repo.clone_from()` and the submodule clones of `Submodule.update()` and `RootModule.update()`, on the URL passed to `Remote.create()`, and on the URL `RootModule.update()` stores for a changed `.gitmodules` entry. In a URL a backslash is an ordinary character, and replacing it can move the end of the authority: - Git (through libcurl) and `urllib.parse` read `http://localhost:18472\@127.0.0.1:18471/lib.git` as userinfo `localhost:18472\` and host `127.0.0.1:18471`. - GitPython handed Git `http://localhost:18472/@127.0.0.1:18471/lib.git`, whose host is `localhost:18472`. With that URL in `.gitmodules` and an HTTP listener on each port, `git submodule update --init` contacted `127.0.0.1:18471`, while `Repo.submodule_update(init=True)` and `Repo.clone_from()` contacted `localhost:18472` on both backends. `Submodule.url` still reported the original string, so a host allowlist checked against that URL, with `urllib` or with Git, did not bound the host GitPython connected to. `.gitmodules` is untrusted repository content, and a service that validates a user-supplied clone URL's host before calling `Repo.clone_from()` is affected the same way. `Submodule.add()` made the same replacement on Windows through `to_native_path_linux()`. `polish_url` now returns a string unchanged when it starts with a URL scheme or scp-style host of at least two characters, using Git's scheme characters, followed by a colon. Strings without such a prefix, including one-letter Windows drive paths, `~` paths and `file:` URLs, are converted exactly as before, and the Cygwin branch is untouched (`cygpath` already leaves URLs such as `https://...` alone). `Submodule.add()` applies the same test before `to_native_path_linux()`. Unsafe-protocol checks still run on the URL Git receives. `test_clone_from_passes_remote_url_unchanged` and `test_polish_url_converts_backslashes_only_in_local_paths` in `test/test_clone.py` fail before the change and pass after on the `cli` and `gix` backends, and every request in the reproduction above now reaches `127.0.0.1:18471`. The full test suite passes on both backends with Git 2.54.0, GixPython 0.3.0 and CPython 3.13 on macOS; `pre-commit`, `mypy`, `basedpyright --warnings` and the Sphinx build pass. The Windows-only `Submodule.add()` path was not exercised on Windows. Agent-Model: claude-opus-5-5
Member
|
Closing this based on the changed contributing guidelines: missing reference to downstream bug or problem. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Git.polish_url ne Cygwin ke bahar URL ke har backslash () ko slash (/) mein badal diya tha. Repo._clone, Remote.create aur RootModule.update har clone ya stored remote URL ko is function se pass karte hain. Ismein .gitmodules se padhe gaye submodule URLs bhi shamil hain.
Git (libcurl ke through) aur urllib ne http://localhost:18472\@127.0.0.1:18471/lib.git ko alag-alag tareeke se samjha. Inhone localhost:18472\ ko userinfo aur 127.0.0.1:18471 ko host maana. Lekin GitPython ne Git ko wahi URL http://localhost:18472/@127.0.0.1:18471/lib.git ke roop mein diya.
Is URL ke saath .gitmodules mein git submodule update --init ne 127.0.0.1:18471 se connection banaya, jabki Repo.submodule_update(init=True) aur Repo.clone_from ne dono backends par localhost:18472 se connection banaya.
Saath hi, Submodule.url mein original string hi dikh rahi thi. Is wajah se URL ke basis par check karne wali host allowlist us host ko sahi tarah verify nahi kar pa rahi thi jisse GitPython actually connect karta hai.
Ab polish_url un strings ko bina badle chhod deta hai jo URL scheme se shuru hoti hain ya jinmein do ya usse zyada characters wala SCP-style host hota hai.
Submodule.add bhi Windows-only to_native_path_linux call se pehle yahi check use karta hai.
Drive-letter paths, ~ paths aur file: URLs pehle ki tarah convert hote rahenge.
test/test_clone.py mein do naye tests add kiye gaye hain. Ye tests dono backends par pehle fail hote the aur ab pass hote hain.
macOS par Git 2.54.0 ke saath full test suite, pre-commit, mypy, basedpyright aur docs build sab successfully pass hue.
Windows-only Submodule.add path ko Windows par run nahi kiya gaya.