Skip to content

Commit b4a0740

Browse files
Potential fix for code scanning alert no. 77: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 74e503f commit b4a0740

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/gitingest/query_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ def _parse_local_dir_path(path_str: str) -> IngestionQuery:
327327
A dictionary containing the parsed details of the file path.
328328
329329
"""
330+
root_path = TMP_BASE_PATH.resolve()
330331
path_obj = Path(path_str).resolve()
332+
if os.path.commonpath([root_path, path_obj]) != str(root_path):
333+
raise InvalidPatternError(f"Path {path_str} escapes the allowed root directory.")
331334
slug = path_obj.name if path_str == "." else path_str.strip("/")
332335
return IngestionQuery(local_path=path_obj, slug=slug, id=str(uuid.uuid4()))
333336

0 commit comments

Comments
 (0)