Potential fix for code scanning alert no. 13: Uncontrolled command line#2
Potential fix for code scanning alert no. 13: Uncontrolled command line#2ArshVermaGit merged 1 commit intomainfrom
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
ArshVermaGit
left a comment
There was a problem hiding this comment.
This is a strong and well-targeted security hardening change that addresses the root cause rather than just patching individual call sites. Enforcing a strict allowlist tied to linked_repos.json, combined with canonicalized path comparison, effectively prevents command execution against arbitrary filesystem paths while preserving existing behavior for legitimate repositories. I particularly like that the fix is implemented centrally within _run_git, ensuring consistent enforcement across all git operations without requiring scattered router-level checks. Handling normalization edge cases (~, relative paths, symlink-like variations) shows good defensive thinking and significantly reduces the risk of bypass techniques. Keeping subprocess.run in list form maintains existing safety guarantees while adding a proper authorization boundary at the service layer. Overall, this is a clean, minimal, and high-impact mitigation that meaningfully improves command execution safety without introducing unnecessary complexity.
Potential fix for https://github.com/ArshVermaGit/SentinelOps-Autonomous-DevOps-AI/security/code-scanning/13
Best fix: enforce a strict allowlist so git commands only run for repositories already present in
linked_repos.json, with canonicalized path comparison to prevent bypasses (relative-path tricks, symlink-ish variations,~, etc.). This preserves existing behavior for legitimate linked repos and blocks arbitrary user-provided paths.Single best implementation in the shown code:
sentinelops-backend/app/services/local_git_service.py, add helper methods to canonicalize paths and check whether a path is linked._run_git, reject execution unlessrepo_pathis in the linked-repo allowlist.get_repo_status, fail early with an"error"response if the requested path is not linked (before calling any git command), and canonicalize the path.subprocess.runlist-style usage as-is (already safer than shell), but add this authorization guard at the service boundary so all three alert variants are addressed centrally.No router changes are strictly required once service-level allowlisting is enforced.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.