diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index b3ecb8114a4..bb1b572e74f 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -52,6 +52,13 @@ func isMigrateURLAllowed(remoteURL string) error { } } + if u.Host == "" { + if !setting.ImportLocalPaths { + return &models.ErrMigrationNotAllowed{Host: ""} + } + return nil + } + if !setting.Migrations.AllowLocalNetworks { addrList, err := net.LookupIP(strings.Split(u.Host, ":")[0]) if err != nil { diff --git a/modules/migrations/migrate_test.go b/modules/migrations/migrate_test.go index 3bad5cfd736..e8b71bb325b 100644 --- a/modules/migrations/migrate_test.go +++ b/modules/migrations/migrate_test.go @@ -31,4 +31,16 @@ func TestMigrateWhiteBlocklist(t *testing.T) { err = isMigrateURLAllowed("https://github.com/go-gitea/gitea.git") assert.Error(t, err) + + old := setting.ImportLocalPaths + setting.ImportLocalPaths = false + + err = isMigrateURLAllowed("/home/foo/bar/goo") + assert.Error(t, err) + + setting.ImportLocalPaths = true + err = isMigrateURLAllowed("/home/foo/bar/goo") + assert.NoError(t, err) + + setting.ImportLocalPaths = old }