Skip to content

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

Merged
ArshVermaGit merged 2 commits into
mainfrom
alert-autofix-32
May 21, 2026
Merged

Potential fix for code scanning alert no. 26: Uncontrolled data used in path expression#25
ArshVermaGit merged 2 commits into
mainfrom
alert-autofix-32

Conversation

@ArshVermaGit
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/ArshVermaGit/SentinelOps-Autonomous-DevOps-AI/security/code-scanning/26

Use canonical-path validation for git_dir itself before any filesystem access.

Best fix in sentinelops-backend/app/services/local_git_service.py inside _validate_repo_path_for_linking:

  • After computing git_dir, compute git_dir_real = os.path.realpath(git_dir).
  • Ensure git_dir_real is inside normalized using os.path.commonpath([git_dir_real, normalized]) == normalized (with ValueError handling).
  • Perform existence/symlink checks on the canonical path (git_dir_real) instead of the raw joined path.

This preserves behavior (still requires a real .git directory 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.

…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>
Copy link
Copy Markdown
Owner Author

@ArshVermaGit ArshVermaGit left a comment

Choose a reason for hiding this comment

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

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.

@ArshVermaGit ArshVermaGit marked this pull request as ready for review May 21, 2026 21:08
@ArshVermaGit ArshVermaGit merged commit 5697bd1 into main May 21, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants