Potential fix for code scanning alert no. 33: Uncontrolled data used in path expression#26
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>
ArshVermaGit
left a comment
There was a problem hiding this comment.
This PR proposes a sensible defense-in-depth improvement for handling uncontrolled path input by shifting validation closer to the router boundary while preserving existing functionality. Validating and canonicalizing req.local_path before invoking link_repo() helps reduce taint propagation into filesystem operations and makes the trust boundary much clearer. Reusing the service-level sanitizer for linking is a practical choice since the existing helper pattern does not fit this flow, and returning the validated canonical path improves consistency in the API response. Overall, the change strengthens input handling without altering the repo-linking behavior and complements the service-layer checks effectively.
Potential fix for https://github.com/ArshVermaGit/SentinelOps-Autonomous-DevOps-AI/security/code-scanning/33
General fix: validate and canonicalize untrusted path input as early as possible (router boundary), and only pass sanitized values into filesystem operations. Keep normalization + containment checks in the service as defense-in-depth.
Best fix here without changing functionality:
sentinelops-backend/app/routers/local_dev.py, update/repos/linkto validatereq.local_pathusing the existing_validated_linked_repo_pathhelper pattern isn’t suitable for link (it requires already linked), so call the service sanitizer for linking and reject invalid input before callinglink_repo.req.local_path) intolocal_git.link_repo(...).This keeps behavior (linking repos) while ensuring path input is sanitized at the trust boundary and reduces taint flow to filesystem sinks.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.