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

Appearance settings

Commit 65b8c6a

Browse filesBrowse files
committed
Add test for CVE-2023-41040
1 parent 64ebb9f commit 65b8c6a
Copy full SHA for 65b8c6a

File tree

1 file changed

+15
-0
lines changed
Filter options

1 file changed

+15
-0
lines changed

‎test/test_refs.py

Copy file name to clipboardExpand all lines: test/test_refs.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
from itertools import chain
8+
from pathlib import Path
89

910
from git import (
1011
Reference,
@@ -20,9 +21,11 @@
2021
from git.objects.tag import TagObject
2122
from test.lib import TestBase, with_rw_repo
2223
from git.util import Actor
24+
from gitdb.exc import BadName
2325

2426
import git.refs as refs
2527
import os.path as osp
28+
import tempfile
2629

2730

2831
class TestRefs(TestBase):
@@ -616,3 +619,15 @@ def test_dereference_recursive(self):
616619

617620
def test_reflog(self):
618621
assert isinstance(self.rorepo.heads.master.log(), RefLog)
622+
623+
def test_refs_outside_repo(self):
624+
# Create a file containing a valid reference outside the repository. Attempting
625+
# to access it should raise an exception, due to it containing a parent directory
626+
# reference ('..'). This tests for CVE-2023-41040.
627+
git_dir = Path(self.rorepo.git_dir)
628+
repo_parent_dir = git_dir.parent.parent
629+
with tempfile.NamedTemporaryFile(dir=repo_parent_dir) as ref_file:
630+
ref_file.write(b"91b464cd624fe22fbf54ea22b85a7e5cca507cfe")
631+
ref_file.flush()
632+
ref_file_name = Path(ref_file.name).name
633+
self.assertRaises(BadName, self.rorepo.commit, f"../../{ref_file_name}")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.