Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(users): require a real email on user-initiated email change
Sergey Kozyrenko497cfdd555b5
diff --git a/backend/pkg/server/models/init.go b/backend/pkg/server/models/init.goindex ed12d0bd..1847252d 100644--- a/backend/pkg/server/models/init.go+++ b/backend/pkg/server/models/init.go@@ -87,8 +87,13 @@ func strongPasswordValidatorString() validator.Func {}}+var emailFormatRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)++func isRealEmail(email string) bool {+ return len(email) > 4 && emailFormatRegex.MatchString(email)+}+func emailValidatorString() validator.Func {- emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)return func(fl validator.FieldLevel) bool {field := fl.Field()@@ -101,13 +106,19 @@ func emailValidatorString() validator.Func {if err := validate.Var(email, "required,uuid"); err == nil {return true}- return len(email) > 4 && emailRegex.MatchString(email)+ return isRealEmail(email)default:return false}}}+func strictEmailValidatorString() validator.Func {+ return func(fl validator.FieldLevel) bool {+ return fl.Field().Kind() == reflect.String && isRealEmail(fl.Field().String())+ }+}+func oauthMinScope() validator.Func {scopeParts := []string{"openid",@@ -213,6 +224,7 @@ func init() {_ = validate.RegisterValidation("semverex", templateValidatorString(semverexRegexString))_ = validate.RegisterValidation("stpass", strongPasswordValidatorString())_ = validate.RegisterValidation("vmail", emailValidatorString())+ _ = validate.RegisterValidation("realemail", strictEmailValidatorString())_ = validate.RegisterValidation("oauth_min_scope", oauthMinScope())_ = validate.RegisterValidation("valid", deepValidator())diff --git a/backend/pkg/server/models/init_test.go b/backend/pkg/server/models/init_test.goindex 9def48bc..bb4eb466 100644--- a/backend/pkg/server/models/init_test.go+++ b/backend/pkg/server/models/init_test.go@@ -81,6 +81,38 @@ func TestEmailValidator(t *testing.T) {}}+func TestStrictEmailValidator(t *testing.T) {+ t.Parallel()++ tests := []struct {+ name string+ email string+ wantErr bool+ }{+ {"valid email", "[email protected]", false},+ {"mixed case", "[email protected]", false},+ {"long tld", "[email protected]", false},+ {"admin sentinel rejected", "admin", true},+ {"bare UUID rejected", "550e8400-e29b-41d4-a716-446655440000", true},+ {"too short", "a@b", true},+ {"empty", "", true},+ {"no at sign", "testexample.com", true},+ }++ for _, tt := range tests {+ tt := tt+ t.Run(tt.name, func(t *testing.T) {+ t.Parallel()+ err := GetValidator().Var(tt.email, "realemail")+ if tt.wantErr {+ assert.Error(t, err)+ } else {+ assert.NoError(t, err)+ }+ })+ }+}+func TestOAuthMinScopeValidator(t *testing.T) {t.Parallel()diff --git a/backend/pkg/server/models/users.go b/backend/pkg/server/models/users.goindex 064aaa42..d5486e4a 100644--- a/backend/pkg/server/models/users.go+++ b/backend/pkg/server/models/users.go@@ -306,7 +306,7 @@ type UserWithPreferences struct {// EmailChange is model to contain user email to change ittype EmailChange struct {CurrentPassword string `form:"current_password" json:"current_password" validate:"min=5,max=100,required" gorm:"-"`- Mail string `form:"mail" json:"mail" validate:"max=50,vmail,required" gorm:"type:TEXT"`+ Mail string `form:"mail" json:"mail" validate:"max=50,realemail,required" gorm:"type:TEXT"`}// TableName returns the table name string to guaranty use correct tablediff --git a/backend/pkg/server/services/users_test.go b/backend/pkg/server/services/users_test.goindex f265c731..0f6f6440 100644--- a/backend/pkg/server/services/users_test.go+++ b/backend/pkg/server/services/users_test.go@@ -425,6 +425,20 @@ func TestChangeEmailCurrentUser(t *testing.T) {expectedCode: http.StatusBadRequest,errorContains: "failed to validate user email",},+ {+ name: "rejects a bare UUID (vmail escape hatch closed for user-set email)",+ requestBody: `{"current_password": "SecurePass123!", "mail": "550e8400-e29b-41d4-a716-446655440000"}`,+ uid: 1,+ expectedCode: http.StatusBadRequest,+ errorContains: "failed to validate user email",+ },+ {+ name: "rejects the admin sentinel for user-set email",+ requestBody: `{"current_password": "SecurePass123!", "mail": "admin"}`,+ uid: 1,+ expectedCode: http.StatusBadRequest,+ errorContains: "failed to validate user email",+ },}for _, tc := range testCases {