Skip to content
Merged
Changes from all 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
17 changes: 9 additions & 8 deletions sentinelops-backend/app/services/local_git_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,14 @@
def _is_within_allowed_root(self, normalized_path: str) -> bool:
"""Return True if normalized_path is inside configured allowed repo root."""
try:
if (
not ALLOWED_REPO_ROOT
or not os.path.isabs(ALLOWED_REPO_ROOT)
or not os.path.isdir(ALLOWED_REPO_ROOT)
):
if not ALLOWED_REPO_ROOT:
return False
return (
os.path.commonpath([normalized_path, ALLOWED_REPO_ROOT])
== ALLOWED_REPO_ROOT
allowed_root = os.path.realpath(
os.path.abspath(os.path.expanduser(ALLOWED_REPO_ROOT))
)
if not os.path.isabs(allowed_root) or not os.path.isdir(allowed_root):
return False
return os.path.commonpath([normalized_path, allowed_root]) == allowed_root
except ValueError:
return False

Expand All @@ -135,6 +133,9 @@
return ""
if not self._is_within_allowed_root(normalized):
return ""
# Do not allow linking via symlinked repository directories.
if os.path.islink(normalized):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return ""
if not os.path.isdir(normalized):
return ""
git_dir = os.path.join(normalized, ".git")
Expand Down
Loading