Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2334ee5

Browse files
committed
Forbid unsafe protocol URLs in Repo.clone_from()
Since the URL is passed directly to git clone, and the remote-ext helperwill happily execute shell commands, so by default disallow URLs thatcontain a "::" unless a new unsafe_protocols kwarg is passed.(CVE-2022-24439)Fixes#1515
1 parent17ff263 commit2334ee5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎git/repo/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ def clone_from(
12531253
progress:Optional[Callable]=None,
12541254
env:Optional[Mapping[str,str]]=None,
12551255
multi_options:Optional[List[str]]=None,
1256+
unsafe_protocols:bool=False,
12561257
**kwargs:Any,
12571258
)->"Repo":
12581259
"""Create a clone from the given URL
@@ -1267,11 +1268,14 @@ def clone_from(
12671268
If you want to unset some variable, consider providing empty string
12681269
as its value.
12691270
:param multi_options: See ``clone`` method
1271+
:param unsafe_protocols: Allow unsafe protocols to be used, like ext
12701272
:param kwargs: see the ``clone`` method
12711273
:return: Repo instance pointing to the cloned directory"""
12721274
git=cls.GitCommandWrapperType(os.getcwd())
12731275
ifenvisnotNone:
12741276
git.update_environment(**env)
1277+
ifnotunsafe_protocolsand"::"inurl:
1278+
raiseValueError(f"{url} requires unsafe_protocols flag")
12751279
returncls._clone(git,url,to_path,GitCmdObjectDB,progress,multi_options,**kwargs)
12761280

12771281
defarchive(

‎test/test_repo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
importpickle
1414
importsys
1515
importtempfile
16+
importuuid
1617
fromunittestimportmock,skipIf,SkipTest
1718

1819
importpytest
@@ -263,6 +264,25 @@ def test_leaking_password_in_clone_logs(self, rw_dir):
263264
to_path=rw_dir,
264265
)
265266

267+
deftest_clone_from_forbids_helper_urls_by_default(self):
268+
withself.assertRaises(ValueError):
269+
Repo.clone_from("ext::sh -c touch% /tmp/foo","tmp")
270+
271+
@with_rw_repo("HEAD")
272+
deftest_clone_from_allow_unsafe(self,repo):
273+
bad_filename=pathlib.Path(f'{tempfile.gettempdir()}/{uuid.uuid4()}')
274+
bad_url=f'ext::sh -c touch%{bad_filename}'
275+
try:
276+
repo.clone_from(
277+
bad_url,'tmp',
278+
multi_options=["-c protocol.ext.allow=always"],
279+
unsafe_protocols=True
280+
)
281+
exceptGitCommandError:
282+
pass
283+
self.assertTrue(bad_filename.is_file())
284+
bad_filename.unlink()
285+
266286
@with_rw_repo("HEAD")
267287
deftest_max_chunk_size(self,repo):
268288
classTestOutputStream(TestBase):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp