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(auth): accept mixed-case and long-TLD emails; normalize on change
Sergey Kozyrenkoc14ba936fbc9
diff --git a/backend/pkg/server/models/init.go b/backend/pkg/server/models/init.goindex e19a595d..ed12d0bd 100644--- a/backend/pkg/server/models/init.go+++ b/backend/pkg/server/models/init.go@@ -88,7 +88,7 @@ func strongPasswordValidatorString() validator.Func {}func emailValidatorString() validator.Func {- emailRegex := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)+ emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)return func(fl validator.FieldLevel) bool {field := fl.Field()diff --git a/backend/pkg/server/models/init_test.go b/backend/pkg/server/models/init_test.goindex b9eaf6de..9def48bc 100644--- a/backend/pkg/server/models/init_test.go+++ b/backend/pkg/server/models/init_test.go@@ -59,6 +59,8 @@ func TestEmailValidator(t *testing.T) {{"valid email", "[email protected]", false},{"admin special case", "admin", false},{"email with subdomain", "[email protected]", false},+ {"mixed case", "[email protected]", false},+ {"long tld", "[email protected]", false},{"email too short", "a@b", true},{"empty email", "", true},{"no at sign", "testexample.com", true},diff --git a/backend/pkg/server/services/users.go b/backend/pkg/server/services/users.goindex 39a50b6a..156c0106 100644--- a/backend/pkg/server/services/users.go+++ b/backend/pkg/server/services/users.go@@ -4,6 +4,7 @@ import ("errors""net/http""slices"+ "strings""pentagi/pkg/server/auth""pentagi/pkg/server/logger"@@ -210,6 +211,8 @@ func (s *UserService) ChangeEmailCurrentUser(c *gin.Context) {return}+ form.Mail = strings.ToLower(strings.TrimSpace(form.Mail))+uid := c.GetUint64("uid")scope := func(db *gorm.DB) *gorm.DB {return db.Where("id = ?", uid)diff --git a/backend/pkg/server/services/users_test.go b/backend/pkg/server/services/users_test.goindex 9de2803f..e4aaa9b2 100644--- a/backend/pkg/server/services/users_test.go+++ b/backend/pkg/server/services/users_test.go@@ -393,6 +393,17 @@ func TestChangeEmailCurrentUser(t *testing.T) {assert.Nil(t, user.Provider, "email change clears the now-stale OAuth provider link")},},+ {+ name: "mixed-case email is stored lowercase",+ requestBody: `{"current_password": "SecurePass123!", "mail": "[email protected]"}`,+ uid: 1,+ expectedCode: http.StatusOK,+ checkResult: func(t *testing.T, db *gorm.DB) {+ var user models.User+ require.NoError(t, db.Where("id = 1").First(&user).Error)+ assert.Equal(t, "[email protected]", user.Mail)+ },+ },{name: "invalid password",requestBody: `{"current_password": "WrongPassword!", "mail": "[email protected]"}`,diff --git a/frontend/src/features/authentication/email-change-form.test.tsx b/frontend/src/features/authentication/email-change-form.test.tsxindex 0213b3f6..e694e03b 100644--- a/frontend/src/features/authentication/email-change-form.test.tsx+++ b/frontend/src/features/authentication/email-change-form.test.tsx@@ -35,7 +35,7 @@ describe('EmailChangeForm', () => {const onSuccess = vi.fn();render(<EmailChangeForm onSuccess={onSuccess} />);- await user.type(screen.getByPlaceholderText('Enter your new email address'), '[email protected]');+ await user.type(screen.getByPlaceholderText('Enter your new email address'), '[email protected]');await user.type(screen.getByPlaceholderText('Enter your current password'), 'Oldpass0!');await user.click(screen.getByRole('button', { name: 'Update Email' }));diff --git a/frontend/src/features/authentication/email-change-form.tsx b/frontend/src/features/authentication/email-change-form.tsxindex 10ed0aaa..4f1ba357 100644--- a/frontend/src/features/authentication/email-change-form.tsx+++ b/frontend/src/features/authentication/email-change-form.tsx@@ -16,6 +16,8 @@ const emailChangeSchema = z.object({currentPassword: z.string().min(1, { message: 'Current password is required' }),newEmail: z.string()+ .trim()+ .toLowerCase().min(1, { message: 'Email is required' }).email({ message: 'Invalid email address' }).max(50, { message: 'Email must not exceed 50 characters' }),