Skip to content

Commit 67f7ffa

Browse files
codexByron
authored andcommitted
reject reference symlink escapes
1 parent 555bef6 commit 67f7ffa

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

git/refs/symbolic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def abspath(self) -> PathLike:
114114
def _get_validated_path(base: PathLike, path: PathLike) -> str:
115115
path = os.fspath(path)
116116
base_path = os.path.realpath(os.fspath(base))
117+
cur_path = base_path
118+
for part in os.path.normpath(path).split(os.sep):
119+
if part in ("", "."):
120+
continue
121+
cur_path = os.path.join(cur_path, part)
122+
if os.path.islink(cur_path):
123+
raise ValueError("Reference path %r escapes the repository" % path)
117124
abs_path = os.path.realpath(os.path.join(base_path, path))
118125
try:
119126
common_path = os.path.commonpath([base_path, abs_path])

0 commit comments

Comments
 (0)