1 parent
8ca7187721
commit
8bd6f1edfb
8 files changed
+286
-21
No files matched your search
@@ -581,12 +581,8 @@ func legacyDatabaseConfig(root string, vault *credential.Vault, legacy legacyMig
|
||||
func legacyDatabasePlan(legacy legacyMigrationConfig) (DatabaseConfig, string, []string) {
|
||||
switch legacy.DbType {
|
||||
case "", DBTypeSQLite:
|
||||
name := strings.TrimSpace(legacy.DbDSN)
|
||||
if name == "" {
|
||||
name = "smail.db"
|
||||
}
|
||||
name = filepath.Base(filepath.Clean(name))
|
||||
if !databaseLocalRefPattern.MatchString(name) {
|
||||
name, ok := legacySQLiteLocalRef(legacy.DbDSN)
|
||||
if !ok {
|
||||
return DatabaseConfig{}, "", []string{"dbDSN"}
|
||||
}
|
||||
return DatabaseConfig{Type: DatabaseTypeSQLite, LocalRef: name}, "", nil
|
||||
@@ -607,6 +603,29 @@ func legacyDatabasePlan(legacy legacyMigrationConfig) (DatabaseConfig, string, [
|
||||
}
|
||||
}
|
||||
|
||||
func legacySQLiteLocalRef(value string) (string, bool) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
value = "smail.db"
|
||||
}
|
||||
if filepath.IsAbs(value) || isWindowsAbsolute(value) {
|
||||
return "", false
|
||||
}
|
||||
value = filepath.ToSlash(value)
|
||||
value = strings.TrimPrefix(value, "./")
|
||||
value = strings.TrimPrefix(value, "config/")
|
||||
if value == "" || strings.HasPrefix(value, "../") || value == ".." || strings.Contains(value, "/../") || strings.Contains(value, "\\") || strings.Contains(value, ":") {
|
||||
return "", false
|
||||
}
|
||||
parts := strings.Split(value, "/")
|
||||
for _, part := range parts {
|
||||
if part == "" || part == "." || !databaseLocalRefPattern.MatchString(part) {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
return value, true
|
||||
}
|
||||
|
||||
func parseLegacyMySQLDSN(value string) (DatabaseConfig, string, bool) {
|
||||
matches := legacyMySQLDSNPattern.FindStringSubmatch(value)
|
||||
if matches == nil {
|
||||
|
||||
@@ -226,6 +226,14 @@ func (s *TransactionStore) Recover() error {
|
||||
if err := validateTransactionFiles(transactionDirectory, "original", manifest.OriginalFiles); err != nil {
|
||||
return err
|
||||
}
|
||||
loader := NewConfigLoader(s.root, ConfigLoaderOptions{Validation: s.validation})
|
||||
runtime, loadErr := loader.Load()
|
||||
if loadErr == nil && runtime.Generation >= manifest.ToGeneration {
|
||||
if err := os.RemoveAll(transactionDirectory); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch manifest.Phase {
|
||||
case TransactionPrepared, TransactionSectionsCommitted:
|
||||
if err := restoreTransactionOriginal(directory, transactionDirectory, manifest); err != nil {
|
||||
@@ -239,14 +247,6 @@ func (s *TransactionStore) Recover() error {
|
||||
return err
|
||||
}
|
||||
case TransactionRootCommitted, TransactionVerified:
|
||||
loader := NewConfigLoader(s.root, ConfigLoaderOptions{Validation: s.validation})
|
||||
runtime, loadErr := loader.Load()
|
||||
if loadErr == nil && runtime.Generation == manifest.ToGeneration {
|
||||
if err := os.RemoveAll(transactionDirectory); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := restoreTransactionOriginal(directory, transactionDirectory, manifest); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func validateDatabase(database DatabaseConfig) error {
|
||||
database = NormalizeDatabaseConfig(database)
|
||||
switch database.Type {
|
||||
case DatabaseTypeSQLite:
|
||||
if !databaseLocalRefPattern.MatchString(database.LocalRef) ||
|
||||
if !validSQLiteLocalRef(database.LocalRef) ||
|
||||
filepath.IsAbs(database.LocalRef) ||
|
||||
isWindowsAbsolute(database.LocalRef) ||
|
||||
strings.ContainsAny(database.LocalRef, `/\\:`) ||
|
||||
@@ -99,6 +99,20 @@ func validateDatabase(database DatabaseConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validSQLiteLocalRef(value string) bool {
|
||||
value = filepath.ToSlash(value)
|
||||
if value == "" || filepath.IsAbs(value) || isWindowsAbsolute(value) || strings.HasPrefix(value, "config/") || strings.ContainsAny(value, `\\:`) {
|
||||
return false
|
||||
}
|
||||
parts := strings.Split(value, "/")
|
||||
for _, part := range parts {
|
||||
if part == "" || part == "." || part == ".." || !databaseLocalRefPattern.MatchString(part) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func validateSMTP(smtp SMTPConfig) error {
|
||||
if !validLoginVerificationPolicy(smtp.LoginPolicy) {
|
||||
return ErrInvalidSMTP
|
||||
|
||||
Reference in new issue
Block a user