Skip to content

Commit 3fbb2b3

Browse files
committed
fix: allow any HTTPS host for dotfiles repo
Remove the 4-host allowlist (github, gitlab, bitbucket, codeberg). Self-hosted GitLab and other git hosts are valid as long as they use HTTPS. Path traversal and format checks are kept.
1 parent bcc21b3 commit 3fbb2b3

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

internal/config/config.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,14 @@ var (
204204
pkgNameRe = regexp.MustCompile(`^[a-zA-Z0-9@/_.-]+$`)
205205
tapNameRe = regexp.MustCompile(`^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$`)
206206

207-
// allowedDotfilesHosts are the only git hosting providers accepted for
208-
// dotfiles repository URLs, matching the server-side validation.
209-
allowedDotfilesHosts = []string{
210-
"github.com",
211-
"gitlab.com",
212-
"bitbucket.org",
213-
"codeberg.org",
214-
}
215-
216207
// dotfilesPathRe validates the path component: one or more segments of
217208
// alphanumeric, dash, underscore, or dot characters separated by slashes.
218209
dotfilesPathRe = regexp.MustCompile(`^/[a-zA-Z0-9._-]+(/[a-zA-Z0-9._-]+)*$`)
219210
)
220211

221-
// ValidateDotfilesURL checks that a dotfiles repo URL conforms to the
222-
// server-side rules: HTTPS only, restricted hosts, max 500 chars, no path
223-
// traversal, and a valid path format.
212+
// ValidateDotfilesURL checks that a dotfiles repo URL uses HTTPS, has a
213+
// valid path, max 500 chars, and no path traversal. Any HTTPS host is
214+
// accepted (including self-hosted GitLab, Gitea, etc.).
224215
func ValidateDotfilesURL(rawURL string) error {
225216
if rawURL == "" {
226217
return nil
@@ -239,16 +230,8 @@ func ValidateDotfilesURL(rawURL string) error {
239230
return fmt.Errorf("dotfiles URL is not a valid URL: %w", err)
240231
}
241232

242-
hostAllowed := false
243-
for _, h := range allowedDotfilesHosts {
244-
if parsed.Hostname() == h {
245-
hostAllowed = true
246-
break
247-
}
248-
}
249-
if !hostAllowed {
250-
return fmt.Errorf("dotfiles URL host %q is not allowed; accepted hosts: %s",
251-
parsed.Hostname(), strings.Join(allowedDotfilesHosts, ", "))
233+
if parsed.Hostname() == "" {
234+
return fmt.Errorf("dotfiles URL is missing a hostname")
252235
}
253236

254237
path := parsed.Path

internal/config/config_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,8 @@ func TestValidateDotfilesURL(t *testing.T) {
585585
wantErr: "must use https://",
586586
},
587587
{
588-
name: "disallowed host",
589-
url: "https://example.com/user/dotfiles",
590-
wantErr: "not allowed",
588+
name: "self-hosted gitlab accepted",
589+
url: "https://gitlab.huami.com/user/dotfiles",
591590
},
592591
{
593592
name: "path traversal rejected",

internal/installer/installer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func stepDotfiles(cfg *config.Config) error {
604604
return err
605605
}
606606
if setup {
607-
dotfilesURL, err = ui.Input("Dotfiles repository URL (https:// only — github.com, gitlab.com, bitbucket.org, codeberg.org)", "https://github.com/username/dotfiles")
607+
dotfilesURL, err = ui.Input("Dotfiles repository URL (https:// only)", "https://github.com/username/dotfiles")
608608
if err != nil {
609609
return err
610610
}

0 commit comments

Comments
 (0)