Potential fix for code scanning alert no. 26: Uncontrolled data used in path expression#25
Merged
Conversation
…in path expression Co-authored-by: Arsh Verma <arshverma.dev@gmail.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| return "" | ||
| # Require a real .git directory inside the repository path and reject symlinks. | ||
| if not os.path.isdir(git_dir) or os.path.islink(git_dir): | ||
| if not os.path.isdir(git_dir_real) or os.path.islink(git_dir_real): |
| return "" | ||
| # Require a real .git directory inside the repository path and reject symlinks. | ||
| if not os.path.isdir(git_dir) or os.path.islink(git_dir): | ||
| if not os.path.isdir(git_dir_real) or os.path.islink(git_dir_real): |
…ed in path expression' Co-authored-by: Arsh Verma <arshverma.dev@gmail.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
ArshVermaGit
commented
May 21, 2026
Owner
Author
ArshVermaGit
left a comment
There was a problem hiding this comment.
This looks like a solid hardening approach for the uncontrolled path usage issue. Validating git_dir through os.path.realpath() before any filesystem interaction makes the protection more explicit and reliable, especially by ensuring the resolved path stays constrained within the normalized repository root using os.path.commonpath(). Moving the existence and symlink checks to operate on the canonical path is a good improvement because it closes potential path traversal or symlink bypass gaps without changing the intended behavior. Overall, the fix feels targeted, preserves existing validation expectations around a real .git directory, and improves security at the actual point of use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/ArshVermaGit/SentinelOps-Autonomous-DevOps-AI/security/code-scanning/26
Use canonical-path validation for
git_diritself before any filesystem access.Best fix in
sentinelops-backend/app/services/local_git_service.pyinside_validate_repo_path_for_linking:git_dir, computegit_dir_real = os.path.realpath(git_dir).git_dir_realis insidenormalizedusingos.path.commonpath([git_dir_real, normalized]) == normalized(withValueErrorhandling).git_dir_real) instead of the raw joined path.This preserves behavior (still requires a real
.gitdirectory and rejects symlinks) while making the sink path explicitly normalized and constrained at point-of-use.Suggested fixes powered by Copilot Autofix. Review carefully before merging.