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

Fix CVE-2023-41040#1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionsgit/refs/symbolic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -168,6 +168,8 @@ def _get_ref_info_helper(
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""
if ".." in str(ref_path):
raise ValueError(f"Invalid reference '{ref_path}'")
tokens: Union[None, List[str], Tuple[str, str]] = None
repodir = _git_dir(repo, ref_path)
try:
Expand Down
15 changes: 15 additions & 0 deletionstest/test_refs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php

from itertools import chain
from pathlib import Path

from git import (
Reference,
Expand All@@ -20,9 +21,11 @@
from git.objects.tag import TagObject
from test.lib import TestBase, with_rw_repo
from git.util import Actor
from gitdb.exc import BadName

import git.refs as refs
import os.path as osp
import tempfile


class TestRefs(TestBase):
Expand DownExpand Up@@ -616,3 +619,15 @@ def test_dereference_recursive(self):

def test_reflog(self):
assert isinstance(self.rorepo.heads.master.log(), RefLog)

def test_refs_outside_repo(self):
# Create a file containing a valid reference outside the repository. Attempting
# to access it should raise an exception, due to it containing a parent directory
# reference ('..'). This tests for CVE-2023-41040.
git_dir = Path(self.rorepo.git_dir)
repo_parent_dir = git_dir.parent.parent
with tempfile.NamedTemporaryFile(dir=repo_parent_dir) as ref_file:
ref_file.write(b"91b464cd624fe22fbf54ea22b85a7e5cca507cfe")
ref_file.flush()
ref_file_name = Path(ref_file.name).name
self.assertRaises(BadName, self.rorepo.commit, f"../../{ref_file_name}")

[8]ページ先頭

©2009-2025 Movatter.jp