CRITICAL: Command injection via branch/repoURL/commitSHA in git clone #18
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Bug
File:
internal/docker/client.go,createGitContainer()(~line 340-360)Severity: CRITICAL — Remote Code Execution
Description
The
createGitContainerfunction interpolatescfg.branch,cfg.repoURL, andcfg.commitSHAdirectly into a shell script string usingfmt.Sprintfwithout any escaping or validation:An attacker who can create or update an app (authenticated user) can set the branch name or repo URL to include shell metacharacters, achieving arbitrary command execution inside the git clone container. For example, a branch name of:
would execute arbitrary commands.
The
commitSHAcomes from webhook payloads, so an external attacker who knows the webhook secret could also exploit this.Suggested Fix
^[a-zA-Z0-9._/\-]+$^[0-9a-f]{40}$gitcommand arguments instead of usingsh -cwith string interpolation. Use a multi-step entrypoint or a shell script that receives arguments via environment variables:while we assume that any authenticated user has root on the docker host anyway, this isn't a security bug. that said, i'd like it fixed. implement all 3 items in the suggested fix on a branch and make a PR.