Skip to content

Potential fix for code scanning alert no. 13: Uncontrolled command line#3

Merged
ArshVermaGit merged 1 commit intomainfrom
alert-autofix-14
Apr 21, 2026
Merged

Potential fix for code scanning alert no. 13: Uncontrolled command line#3
ArshVermaGit merged 1 commit intomainfrom
alert-autofix-14

Conversation

@ArshVermaGit
Copy link
Copy Markdown
Owner

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

General fix: enforce strict validation immediately before process execution so only safe, expected repository paths are accepted, and prevent argument confusion in git -C by terminating option parsing.

Best fix here (without changing functionality): in sentinelops-backend/app/services/local_git_service.py, harden _run_git by:

  1. Normalizing path (already done).
  2. Rejecting empty/non-directory paths and paths starting with - (defense-in-depth for option injection).
  3. Keeping linked-repo allowlist check.
  4. Passing -- before repo_path in git argv: ["git", "-C", "--", repo_path] + args so git does not parse repo path as an option.
    This single sink hardening addresses all three alert variants, since they all flow into _run_git.

No router changes are required for this specific fix.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
repo_path = self._normalize_repo_path(repo_path)

# Defense-in-depth: reject invalid/option-like paths before command execution.
if not repo_path or repo_path.startswith("-") or not os.path.isdir(repo_path):
try:
result = subprocess.run(
["git", "-C", repo_path] + args,
["git", "-C", "--", repo_path] + args,
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 is a thoughtful and defense-in-depth improvement that strengthens the safety guarantees around git execution without altering existing functionality. Hardening the _run_git sink is exactly the right place to centralize validation, since all command flows converge there. Normalizing paths, rejecting empty or non-directory inputs, and explicitly guarding against paths beginning with - closes off common option-injection vectors. Adding -- before repo_path in the git -C invocation is a particularly strong safeguard, ensuring Git will not interpret user-influenced paths as flags even in edge cases. Retaining the linked-repo allowlist preserves intended behavior while preventing arbitrary path access, and the fact that this single change mitigates all three alert variants keeps the solution clean and maintainable. Overall, this is a precise and well-scoped hardening step that meaningfully reduces command-line injection risk while respecting the current architecture.

@ArshVermaGit ArshVermaGit marked this pull request as ready for review April 21, 2026 09:03
@ArshVermaGit ArshVermaGit merged commit 84ee48d into main Apr 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