feat: check if the secret in config/share.yml has been changed during registration.

This commit is contained in:
icey-yu 2025-03-12 17:41:59 +08:00
parent e76e02fdba
commit ca12e25e91
3 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,10 @@ import (
"google.golang.org/grpc"
)
const (
defaultSecret = "openIM123"
)
type userServer struct {
pbuser.UnimplementedUserServer
online cache.OnlineCache
@ -273,6 +277,10 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR
if len(req.Users) == 0 {
return nil, errs.ErrArgs.WrapMsg("users is empty")
}
// check if secret is changed
if s.config.Share.Secret == defaultSecret {
return nil, servererrs.ErrSecretNotChanged.Wrap()
}
if err = authverify.CheckAdmin(ctx, s.config.Share.IMAdminUserID); err != nil {
return nil, err

View File

@ -38,6 +38,9 @@ const (
// General error codes.
const (
NoError = 0 // No error
SecretNotChangedError = 50 // secret not changed
DatabaseError = 90002 // Database error (redis/mysql, etc.)
NetworkError = 90004 // Network error
DataError = 90007 // Data error

View File

@ -17,6 +17,8 @@ package servererrs
import "github.com/openimsdk/tools/errs"
var (
ErrSecretNotChanged = errs.NewCodeError(SecretNotChangedError, "secret not changed, please change secret in config/share.yml for security reasons")
ErrDatabase = errs.NewCodeError(DatabaseError, "DatabaseError")
ErrNetwork = errs.NewCodeError(NetworkError, "NetworkError")
ErrCallback = errs.NewCodeError(CallbackError, "CallbackError")