Skip to content

Commit 64ebb9f

Browse files
committed
This change adds a check during reference resolving to see if it contains an up-level reference ('..'). If it does, it raises an exception. This fixes CVE-2023-41040, which allows an attacker to access files outside the repository's directory.
1 parent 91b464c commit 64ebb9f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Diff for: git/refs/symbolic.py

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def _get_ref_info_helper(
168168
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
169169
rela_path points to, or None. target_ref_path is the reference we
170170
point to, or None"""
171+
if ".." in str(ref_path):
172+
raise ValueError(f"Invalid reference '{ref_path}'")
171173
tokens: Union[None, List[str], Tuple[str, str]] = None
172174
repodir = _git_dir(repo, ref_path)
173175
try:

0 commit comments

Comments
 (0)