Skip to content

Commit

Permalink
chore(ui): enhanced email and password length constraints in basic au…
Browse files Browse the repository at this point in the history
…thentication (#4261)
  • Loading branch information
frankzengjj authored Jul 22, 2024
1 parent f424148 commit 333ca93
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ui/src/components/admin/stats/BasicAuthPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<el-form-item
:label="$t('password')"
required
prop="password"
>
<el-input v-model="form.password" type="password" show-password />
</el-form-item>
Expand Down Expand Up @@ -62,6 +63,28 @@
trigger: ["blur"],
pattern: "^$|^[a-zA-Z0-9_!#$%&’*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"
},
{
validator: (rule, value, callback) => {
if (value && value.length > 256) {
callback(new Error(this.$t("email length constraint")));
} else {
callback();
}
},
trigger: ["blur", "change"]
}
],
password: [
{
validator: (rule, value, callback) => {
if (value && value.length > 256) {
callback(new Error(this.$t("password length constraint")));
} else {
callback();
}
},
trigger: ["blur", "change"]
}
],
confirmPassword: [
{
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
"email": "Email",
"password": "Password",
"confirm password": "Confirm password",
"email length constraint": "Email must not exceed 256 characters",
"password length constraint": "Password must not exceed 256 characters",
"passwords do not match": "Passwords do not match",
"avg duration": "Avg. execution duration",
"neutral trend": "Stable",
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@
"email": "Email",
"password": "Mot de passe",
"confirm password": "Confirmer le mot de passe",
"email length constraint": "L'e-mail ne doit pas dépasser 256 caractères.",
"password length constraint": "Le mot de passe ne doit pas dépasser 256 caractères.",
"passwords do not match": "Les mots de passe ne correspondent pas",
"avg duration": "Durée moyenne d'exécution",
"neutral trend": "Stable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class BasicAuthService {
public static final String BASIC_AUTH_SETTINGS_KEY = "kestra.server.basic-auth";
private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9_!#$%&’*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$");
private static final int EMAIL_PASSWORD_MAX_LEN = 256;

@Inject
private SettingRepositoryInterface settingRepository;
Expand Down Expand Up @@ -75,6 +76,12 @@ public void save(String uid, BasicAuthConfiguration basicAuthConfiguration) {
throw new IllegalArgumentException("No password set for Basic Authentication. Please provide a password.");
}

if (basicAuthConfiguration.getUsername().length() > EMAIL_PASSWORD_MAX_LEN ||
basicAuthConfiguration.password.length() > EMAIL_PASSWORD_MAX_LEN) {
throw new IllegalArgumentException("The length of email or password should not exceed 256 characters.");
}


SaltedBasicAuthConfiguration previousConfiguration = this.configuration();
String salt = previousConfiguration == null
? null
Expand Down

0 comments on commit 333ca93

Please sign in to comment.