Skip to content

fix: Potential fix for code scanning alert no. 77: Uncontrolled data used in path expression #422

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions src/gitingest/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
import re
import uuid
import warnings
Expand Down Expand Up @@ -326,8 +327,17 @@ def _parse_local_dir_path(path_str: str) -> IngestionQuery:
IngestionQuery
A dictionary containing the parsed details of the file path.

Raises
------
InvalidPatternError
If the path escapes the allowed root directory.

"""
root_path = TMP_BASE_PATH.resolve()

This comment was marked as outdated.

path_obj = Path(path_str).resolve()
if os.path.commonpath([root_path, path_obj]) != str(root_path):
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison converts root_path to string but uses the Path object directly in the commonpath call. This could lead to inconsistent behavior. Consider using str(root_path) consistently or compare Path objects directly.

Suggested change
if os.path.commonpath([root_path, path_obj]) != str(root_path):
if os.path.commonpath([str(root_path), str(path_obj)]) != str(root_path):

Copilot uses AI. Check for mistakes.

msg = f"Path {path_str} escapes the allowed root directory."
raise InvalidPatternError(msg)
slug = path_obj.name if path_str == "." else path_str.strip("/")
return IngestionQuery(local_path=path_obj, slug=slug, id=str(uuid.uuid4()))

Expand Down
Loading