Skip to content

Commit da8a17c

Browse files
committed
Document something found by copilot
1 parent cb12ca9 commit da8a17c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

sql/mysql_db/mysql_db.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,18 @@ func (db *MySQLDb) AddRootAccount() {
223223

224224
// AddSuperUser adds the given username and password to the list of accounts. This is a temporary function, which is
225225
// meant to replace the "auth.New..." functions while the remaining functions are added.
226+
//
227+
// SECURITY NOTE: This function uses SHA1 as required by MySQL's mysql_native_password protocol.
228+
// SHA1 is cryptographically weak and should not be used for new implementations.
229+
// Consider using caching_sha2_password or a custom PlaintextAuthPlugin with stronger hashing (e.g., bcrypt, argon2)
230+
// for production environments. This implementation is provided for MySQL protocol compatibility.
231+
//
232+
// Deprecated: Use more secure authentication plugins instead of mysql_native_password.
226233
func (db *MySQLDb) AddSuperUser(username string, host string, password string) {
227234
//TODO: remove this function and the called function
228235
db.Enabled = true
229236
if len(password) > 0 {
237+
// #nosec G401 - SHA1 required for MySQL mysql_native_password protocol compatibility
230238
hash := sha1.New()
231239
hash.Write([]byte(password))
232240
s1 := hash.Sum(nil)
@@ -688,6 +696,8 @@ func columnTemplate(name string, source string, isPk bool, template *sql.Column)
688696
}
689697

690698
// validateMysqlNativePassword was taken directly from vitess and validates the password hash for "mysql_native_password".
699+
// NOTE: This implements MySQL's mysql_native_password protocol which uses SHA1. This is a MySQL protocol requirement,
700+
// not a design choice. For better security, use caching_sha2_password or custom authentication plugins.
691701
func validateMysqlNativePassword(authResponse, salt []byte, mysqlNativePassword string) bool {
692702
// SERVER: recv(authResponse)
693703
// hash_stage1=xor(authResponse, sha1(salt,hash))
@@ -706,6 +716,7 @@ func validateMysqlNativePassword(authResponse, salt []byte, mysqlNativePassword
706716
}
707717

708718
// scramble = SHA1(salt+hash)
719+
// #nosec G401 - SHA1 required for MySQL mysql_native_password protocol compatibility
709720
crypt := sha1.New()
710721
crypt.Write(salt)
711722
crypt.Write(hash)

0 commit comments

Comments
 (0)