fix(migration): omit duplicate values from unique-index repair error

address pr-swarm finding: the error embedded raw row values; unique columns
can hold secrets (token hashes, oauth codes), so report only the count
This commit is contained in:
kolaente
2026-07-20 13:13:46 +02:00
parent a56a53f1d2
commit b1f147deb9
+4 -3
View File
@@ -133,15 +133,16 @@ func ensureNoDuplicates20260720120000(tx *xorm.Engine, table string, cols []stri
query := "SELECT " + strings.Join(quoted, ", ") + " FROM " + tx.Quote(table) +
" WHERE " + strings.Join(notNull, " AND ") +
" GROUP BY " + strings.Join(quoted, ", ") +
" HAVING COUNT(*) > 1 LIMIT 1"
" HAVING COUNT(*) > 1"
rows, err := tx.QueryString(query)
if err != nil {
return err
}
if len(rows) > 0 {
// Some unique-indexed columns hold secrets (token_hash, oauth codes, ...) — never log the values.
return fmt.Errorf(
"cannot recreate the unique index on %s (%s) because duplicate values exist, for example %v — remove the duplicates manually, then restart Vikunja",
table, strings.Join(cols, ", "), rows[0])
"cannot recreate the unique index on %s (%s) because %d sets of duplicate values exist — remove the duplicates manually, then restart Vikunja",
table, strings.Join(cols, ", "), len(rows))
}
return nil
}