fix(init): route --remote through validated git.SetOrAddRemote

The CLI addRemote ran a raw "git remote add origin <url>" with the
user-supplied URL, sharing the argv flag-smuggling risk just fixed in the
git package. Delegate to git.SetOrAddRemote so the --remote flag goes
through the same leading-dash rejection and "--" terminator, removing the
duplicated exec path.
This commit is contained in:
Willie
2026-05-30 19:23:12 +08:00
parent 56766b024c
commit e158f77f03
+4 -3
View File
@@ -1214,9 +1214,10 @@ func setupGitRemote(sourcePath, remoteURL string, dryRun bool) bool {
}
func addRemote(sourcePath, remoteURL string) bool {
cmd := exec.Command("git", "remote", "add", "origin", remoteURL)
cmd.Dir = sourcePath
if err := cmd.Run(); err != nil {
// SetOrAddRemote validates the URL (rejecting flag-smuggling values that
// begin with "-") and passes "--" before positional args. setupGitRemote
// has already confirmed origin is absent, so this takes the add path.
if err := gitops.SetOrAddRemote(sourcePath, remoteURL); err != nil {
ui.Warning("Failed to add remote: %v", err)
return false
}