Fix command injection in git clone arguments (closes #18) #29
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/upaas#29
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch ":fix/command-injection-git-clone"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes command injection vulnerability in
createGitContainer()wherecfg.branch,cfg.repoURL, andcfg.commitSHAwere interpolated directly into a shell script string viafmt.Sprintf.Changes
All 3 suggested fixes from #18 implemented:
^[a-zA-Z0-9._/\-]+$^[0-9a-f]{40}$(when provided)CLONE_URL,CLONE_BRANCH,CLONE_SHAenv vars and properly quoted in the shell script ("$CLONE_BRANCH"etc.)Tests
New test file
internal/docker/validation_test.gowith:CloneReporejects malicious inputs before reaching DockerAll existing tests pass. The webhook test suite also exercises the new validation (short SHA rejection).
Notes
As noted in the issue, this is not exploitable by unauthenticated users (authenticated users already have root on the Docker host), but it is still worth fixing for defense in depth.
- Validate branch names against ^[a-zA-Z0-9._/\-]+$ - Validate commit SHAs against ^[0-9a-f]{40}$ - Pass repo URL, branch, and SHA via environment variables instead of interpolating into shell script string - Add comprehensive tests for validation and injection rejectionTest Results
All tests pass: