Skip to content

Commit bf6b909

Browse files
committed
fixed-username-checks
1 parent c0c93c1 commit bf6b909

6 files changed

Lines changed: 27 additions & 18 deletions

File tree

chaoscenter/authentication/api/handlers/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type ErrStrictPasswordPolicyViolation struct {
110110

111111
type ErrStrictUsernamePolicyViolation struct {
112112
Code int `json:"code" example:"401"`
113-
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 16 characters long."`
113+
Message string `json:"message" example:"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 . _ - @ +"`
114114
}
115115

116116
type ErrEmptyProjectName struct {

chaoscenter/authentication/pkg/utils/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var ErrorDescriptions = map[AppError]string{
5555
ErrUnauthorized: "The user does not have requested authorization to access this resource",
5656
ErrUserExists: "This username is already assigned to another user",
5757
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",
58-
ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 16 characters long.",
58+
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 . _ - @ +",
5959
ErrEmptyProjectName: "Project name can't be empty",
6060
ErrInvalidRole: "Role is invalid",
6161
ErrProjectNotFound: "This project does not exist",

chaoscenter/authentication/pkg/utils/sanitizers.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ func RandomString(n int) (string, error) {
6363
return "", fmt.Errorf("length should be greater than 0")
6464
}
6565

66-
// Username must start with a letter - ^[a-zA-Z]
67-
// Allow letters, digits, underscores, and hyphens - [a-zA-Z0-9_-]
68-
// Ensure the length of the username is between 3 and 16 characters (1 character is already matched above) - {2,15}$
66+
// Username must start with a letter or digit - ^[a-zA-Z0-9]
67+
// Allow letters, digits, and the characters . _ - @ + (so an email address is a valid username,
68+
// which is required for Dex SSO where the email is used as the username) - [a-zA-Z0-9._@+-]
69+
// Ensure the length of the username is between 3 and 254 characters
70+
// (1 character is already matched above, and 254 is the RFC 5321 maximum email length) - {2,253}$
6971

7072
func ValidateStrictUsername(username string) error {
71-
// Ensure username doesn't contain special characters (only letters, numbers, and underscores are allowed)
72-
if matched, _ := regexp.MatchString(`^[a-zA-Z][a-zA-Z0-9_-]{2,15}$`, username); !matched {
73-
return fmt.Errorf("username can only contain letters, numbers, and underscores")
73+
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9][a-zA-Z0-9._@+-]{2,253}$`, username); !matched {
74+
return fmt.Errorf("username can only contain letters, digits, and the characters . _ - @ +")
7475
}
7576

7677
return nil

chaoscenter/web/src/constants/validation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// ^[a-zA-Z] # Must start with a letter
2-
// [a-zA-Z0-9_-] # Allow letters, digits, underscores, and hyphens
3-
// {2,15}$ # Ensure the length of the username is between 3 and 16 characters (1 character is already matched above)
4-
export const USERNAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_-]{2,15}$/;
1+
// ^[a-zA-Z0-9] # Must start with a letter or digit
2+
// [a-zA-Z0-9._@+-] # Allow letters, digits, and the characters . _ - @ + (so emails are valid usernames for Dex SSO correlation)
3+
// {2,253}$ # Ensure the length of the username is between 3 and 254 characters (1 character is already matched above; 254 is the RFC 5321 max email length)
4+
export const USERNAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9._@+-]{2,253}$/;
55

66
// ^(?=.*[a-z]) # At least one lowercase letter
77
// (?=.*[A-Z]) # At least one uppercase letter

chaoscenter/web/src/strings/strings.en.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ copiedToClipboard: Copied to clipboard
199199
copyPrompt: >-
200200
Copy the downloaded YML to a machine where you have kubectl installed and have
201201
access to your Kubernetes cluster.
202-
copyPrompt1: 2. Apply the Chaos CRDs manually
202+
copyPrompt1: 2. Apply the Chaos CRD manually
203203
copyPrompt2: >-
204204
3. Copy the downloaded YML to a machine where you have kubectl installed and
205205
have access to your Kubernetes cluster.
@@ -480,13 +480,19 @@ hypothesis: hypothesis
480480
id: ID
481481
idlowerCase: id
482482
imageRegistry: Image Registry
483-
imageRegistryNameInvalid: 'Registry name must be a valid hostname (e.g., docker.io, gcr.io, my-registry.example.com:5000)'
483+
imageRegistryNameInvalid: >-
484+
Registry name must be a valid hostname (e.g., docker.io, gcr.io,
485+
my-registry.example.com:5000)
484486
imageRegistryNameRequired: Registry name is required for custom image registry
485487
imageRegistryUpdateSuccess: Image Registry added successfully
486-
imageRepoNameInvalid: 'Repository name must contain only lowercase letters, numbers, dots, underscores, slashes, and hyphens'
488+
imageRepoNameInvalid: >-
489+
Repository name must contain only lowercase letters, numbers, dots,
490+
underscores, slashes, and hyphens
487491
imageRepoNameRequired: Repository name is required for custom image registry
488492
imageSecret: Image Secret
489-
imageSecretNameInvalid: 'Secret name must be a valid Kubernetes name (lowercase letters, numbers, dots, and hyphens)'
493+
imageSecretNameInvalid: >-
494+
Secret name must be a valid Kubernetes name (lowercase letters, numbers, dots,
495+
and hyphens)
490496
imageSecretNameRequired: Secret name is required for private image registry
491497
imageSecretPlaceholder: Enter your Image Secret
492498
improveResilienceOfTheDeployedService: Improve resilience of the deployed service
@@ -1220,7 +1226,9 @@ userCreatedOn: User Created On
12201226
userManagement: User Management
12211227
username: Username
12221228
usernameIsRequired: Username is a required field
1223-
usernameValidText: Username can only contain letters, digits, underscores, and hyphens
1229+
usernameValidText: >-
1230+
Username must start with a letter or digit and can only contain letters,
1231+
digits, and the characters . _ - @ +
12241232
usersNotAvailableMessage: No users available to send invitation
12251233
usersNotAvailableTitle: No users available
12261234
validationError: Validation Error

chaoscenter/web/src/views/CreateNewUser/CreateNewUser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function CreateNewUserView(props: CreateNewUserViewProps): React.
7474
username: Yup.string()
7575
.required(getString('usernameIsRequired'))
7676
.min(3, getString('fieldMinLength', { length: 3 }))
77-
.max(16, getString('fieldMaxLength', { length: 16 }))
77+
.max(254, getString('fieldMaxLength', { length: 254 }))
7878
.matches(USERNAME_REGEX, getString('usernameValidText')),
7979
password: Yup.string().required(getString('passwordIsRequired')),
8080
reEnterPassword: Yup.string()

0 commit comments

Comments
 (0)