Skip to content

fixed-username-checks#5503

Open
yashgoyal0110 wants to merge 7 commits into
litmuschaos:masterfrom
yashgoyal0110:fix/username-checks-fixes
Open

fixed-username-checks#5503
yashgoyal0110 wants to merge 7 commits into
litmuschaos:masterfrom
yashgoyal0110:fix/username-checks-fixes

Conversation

@yashgoyal0110
Copy link
Copy Markdown
Contributor

@yashgoyal0110 yashgoyal0110 commented May 6, 2026

Proposed changes

Fixes #5413

The auth API's username validator (ValidateStrictUsername) enforced ^[a-zA-Z][a-zA-Z0-9_-]{2,15}$ — i.e., 3–16 chars, alphanumerics + _- only, must start with a letter. This made it impossible to pre-create a user whose username is their email address (e.g. john.smith.long@example.com), which is required to correlate Dex SSO logins with pre-created accounts. Dex sets Username = claims.Email in dex_auth_handler.go#L127, so any email longer than 16 characters or containing @/. was rejected by /create_user with 401 username_policy_violation.

Files touched

  • chaoscenter/authentication/pkg/utils/sanitizers.go
  • chaoscenter/authentication/pkg/utils/errors.go
  • chaoscenter/authentication/api/handlers/doc.go
  • chaoscenter/web/src/constants/validation.ts
  • chaoscenter/web/src/strings/strings.en.yaml
  • chaoscenter/web/src/views/CreateNewUser/CreateNewUser.tsx

Types of changes

  • Bugfix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Signed-off-by: yashgoyal0110 <yg364550@gmail.com>
@yashgoyal0110 yashgoyal0110 force-pushed the fix/username-checks-fixes branch from bf6b909 to 56aa882 Compare May 6, 2026 18:20
Signed-off-by: yashgoyal0110 <yg364550@gmail.com>
Signed-off-by: yashgoyal0110 <yg364550@gmail.com>
Signed-off-by: yashgoyal0110 <yg364550@gmail.com>
Signed-off-by: yashgoyal0110 <yg364550@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR relaxes username validation so pre-created users can use email-style usernames for Dex SSO correlation.

Changes:

  • Expands backend and frontend username validation from 3–16 chars to 3–254 chars.
  • Allows digits as the first character and permits . _ - @ + in usernames.
  • Updates user-facing validation/error text and API documentation examples.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
chaoscenter/authentication/pkg/utils/sanitizers.go Updates strict username regex and validator error text.
chaoscenter/authentication/pkg/utils/errors.go Updates username policy violation description.
chaoscenter/authentication/api/handlers/doc.go Updates API documentation example for username validation errors.
chaoscenter/web/src/constants/validation.ts Updates frontend username regex.
chaoscenter/web/src/views/CreateNewUser/CreateNewUser.tsx Raises UI username max length to 254.
chaoscenter/web/src/strings/strings.en.yaml Updates username validation copy and reformats related strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +74
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9][a-zA-Z0-9._@+-]{2,253}$`, username); !matched {
return fmt.Errorf("username can only contain letters, digits, and the characters . _ - @ +")
Comment on lines +77 to 78
.max(254, getString('fieldMaxLength', { length: 254 }))
.matches(USERNAME_REGEX, getString('usernameValidText')),
type ErrStrictUsernamePolicyViolation struct {
Code int `json:"code" example:"401"`
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 16 characters long."`
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 254 characters long, must start with letter or digit, and can only contain letters, digits, and the characters . - _ @ +"`
ErrUserExists: "This username is already assigned to another user",
ErrStrictPasswordPolicyViolation: "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 16 characters long.",
ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 254 characters long, must start with a letter or digit, and can only contain letters, digits, and the characters . _ - @ +",
type ErrStrictUsernamePolicyViolation struct {
Code int `json:"code" example:"401"`
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 16 characters long."`
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 254 characters long, must start with letter or digit, and can only contain letters, digits, and the characters . - _ @ +"`
Comment on lines +73 to +74
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9][a-zA-Z0-9._@+-]{2,253}$`, username); !matched {
return fmt.Errorf("username can only contain letters, digits, and the characters . _ - @ +")
@PriteshKiri
Copy link
Copy Markdown
Contributor

@yashgoyal0110 could you please review the comments by co-pilot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot Use Email as Username Due to 16-Character Limit in User Creation API

3 participants