-
Notifications
You must be signed in to change notification settings - Fork 987
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -327,7 +327,10 @@ def _parse_local_dir_path(path_str: str) -> IngestionQuery: | |||||||||||||||||||||||||||||
| A dictionary containing the parsed details of the file path. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| root_path = TMP_BASE_PATH.resolve() | ||||||||||||||||||||||||||||||
| path_obj = Path(path_str).resolve() | ||||||||||||||||||||||||||||||
| if os.path.commonpath([root_path, path_obj]) != str(root_path): | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| if os.path.commonpath([root_path, path_obj]) != str(root_path): | |
| if os.path.commonpath([str(root_path), str(path_obj)]) != str(root_path): |
Outdated
Copilot
AI
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path validation logic has a potential issue: os.path.commonpath() can raise ValueError if the paths are on different drives (Windows) or if the list is empty. Consider wrapping this in a try-except block and also verify that both paths exist before comparison.
| if os.path.commonpath([root_path, path_obj]) != str(root_path): | |
| raise InvalidPatternError(f"Path {path_str} escapes the allowed root directory.") | |
| # Ensure both paths exist | |
| if not root_path.exists() or not path_obj.exists(): | |
| raise InvalidPatternError(f"One or both paths do not exist: {root_path}, {path_obj}") | |
| # Check if path_obj is within root_path | |
| try: | |
| if os.path.commonpath([root_path, path_obj]) != str(root_path): | |
| raise InvalidPatternError(f"Path {path_str} escapes the allowed root directory.") | |
| except ValueError as e: | |
| raise InvalidPatternError(f"Invalid path comparison: {e}") | |
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.