diff --git a/agent/app/service/database.go b/agent/app/service/database.go index f2071ee02..e9104bd0e 100644 --- a/agent/app/service/database.go +++ b/agent/app/service/database.go @@ -5,12 +5,14 @@ import ( "fmt" "os" "path" + "strings" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" + "github.com/1Panel-dev/1Panel/agent/utils/cmd" "github.com/1Panel-dev/1Panel/agent/utils/encrypt" "github.com/1Panel-dev/1Panel/agent/utils/mysql" "github.com/1Panel-dev/1Panel/agent/utils/mysql/client" @@ -126,6 +128,9 @@ func (u *DatabaseService) LoadItems(dbType string) ([]dto.DatabaseItem, error) { } func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool { + if (req.Type == constant.AppMysql || req.Type == constant.AppMariaDB || req.Type == constant.AppPostgresql || req.Type == constant.AppMongodb) && (cmd.CheckIllegal(req.Username, req.Password) || strings.Contains(req.Password, " ")) { + return false + } if req.Timeout == 0 { req.Timeout = 30 } @@ -180,6 +185,9 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool { } func (u *DatabaseService) Create(req dto.DatabaseCreate) error { + if (req.Type == constant.AppMysql || req.Type == constant.AppMariaDB || req.Type == constant.AppPostgresql || req.Type == constant.AppMongodb) && (cmd.CheckIllegal(req.Username, req.Password) || strings.Contains(req.Password, " ")) { + return buserr.New("ErrCmdIllegal") + } if req.Timeout == 0 { req.Timeout = 30 } @@ -303,6 +311,9 @@ func (u *DatabaseService) Delete(req dto.DatabaseDelete) error { } func (u *DatabaseService) Update(req dto.DatabaseUpdate) error { + if (req.Type == constant.AppMysql || req.Type == constant.AppMariaDB || req.Type == constant.AppPostgresql || req.Type == constant.AppMongodb) && (cmd.CheckIllegal(req.Username, req.Password) || strings.Contains(req.Password, " ")) { + return buserr.New("ErrCmdIllegal") + } switch req.Type { case constant.AppPostgresql: if _, err := postgresql.NewPostgresqlClient(pgclient.DBInfo{ diff --git a/agent/app/service/database_mongodb.go b/agent/app/service/database_mongodb.go index 2e61aab9e..b5e5ba6bb 100644 --- a/agent/app/service/database_mongodb.go +++ b/agent/app/service/database_mongodb.go @@ -64,7 +64,7 @@ func (u *MongodbService) UpdateDescription(req dto.UpdateDescription) error { } func (u *MongodbService) Create(ctx context.Context, req dto.MongodbDBCreate) (*model.DatabaseMongodb, error) { - if cmd.CheckIllegal(req.Name, req.Username, req.Password) { + if cmd.CheckIllegal(req.Name, req.Username, req.Password) || strings.Contains(req.Password, " ") { return nil, buserr.New("ErrCmdIllegal") } if !isSupportedMongodbPrivilege(req.Permission) { @@ -146,7 +146,7 @@ func (u *MongodbService) LoadFromRemote(req dto.MongodbLoadDB) error { } func (u *MongodbService) BindUser(req dto.MongodbBind) error { - if cmd.CheckIllegal(req.Database, req.Name, req.Username, req.Password) { + if cmd.CheckIllegal(req.Database, req.Name, req.Username, req.Password) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } @@ -168,7 +168,7 @@ func (u *MongodbService) BindUser(req dto.MongodbBind) error { } func (u *MongodbService) ChangePassword(req dto.MongodbPassword) error { - if cmd.CheckIllegal(req.Database, req.Name, req.Password) { + if cmd.CheckIllegal(req.Database, req.Name, req.Password) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } @@ -190,7 +190,7 @@ func (u *MongodbService) ChangePassword(req dto.MongodbPassword) error { } func (u *MongodbService) ChangeRootPassword(req dto.ChangeDBInfo) error { - if cmd.CheckIllegal(req.Value) { + if cmd.CheckIllegal(req.Value) || strings.Contains(req.Value, " ") { return buserr.New("ErrCmdIllegal") } if req.From != constant.AppResourceLocal { diff --git a/agent/app/service/database_mysql.go b/agent/app/service/database_mysql.go index f7ac9d259..d6e988477 100644 --- a/agent/app/service/database_mysql.go +++ b/agent/app/service/database_mysql.go @@ -437,7 +437,7 @@ func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*mode } func (u *MysqlService) create(ctx context.Context, req dto.MysqlDBCreate, mcpBounded bool) (*model.DatabaseMysql, error) { - if cmd.CheckIllegal(req.Name, req.Username, req.Password, req.Format, req.Collation, req.Permission) { + if cmd.CheckIllegal(req.Name, req.Username, req.Password, req.Format, req.Collation, req.Permission) || strings.Contains(req.Password, " ") { return nil, buserr.New("ErrCmdIllegal") } if len(req.Username) != 0 && len(req.Password) == 0 { @@ -680,7 +680,7 @@ func (u *MysqlService) ListGrantSummary(req dto.MysqlGrantSummarySearch) (map[st } func (u *MysqlService) CreateUser(req dto.MysqlUserCreate) error { - if cmd.CheckIllegal(req.Username, req.Password, req.Host) { + if cmd.CheckIllegal(req.Username, req.Password, req.Host) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } dbs := make([]string, 0, len(req.DBs)) @@ -883,7 +883,7 @@ func (u *MysqlService) UpdateUser(req dto.MysqlUserUpdate) error { } func (u *MysqlService) ChangeUserPassword(req dto.MysqlUserPassword) error { - if cmd.CheckIllegal(req.Username, req.Host, req.Password) { + if cmd.CheckIllegal(req.Username, req.Host, req.Password) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } if err := checkMysqlNormalUser(req.Username); err != nil { @@ -936,7 +936,7 @@ func (u *MysqlService) ChangeUserPassword(req dto.MysqlUserPassword) error { } func (u *MysqlService) SaveUserPassword(req dto.MysqlUserPassword) error { - if cmd.CheckIllegal(req.Username, req.Host, req.Password) { + if cmd.CheckIllegal(req.Username, req.Host, req.Password) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } if err := checkMysqlNormalUser(req.Username); err != nil { @@ -1302,7 +1302,7 @@ func isMysqlDatabaseResourceInUseError(err error) bool { } func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { - if cmd.CheckIllegal(req.Value) { + if cmd.CheckIllegal(req.Value) || strings.Contains(req.Value, " ") { return buserr.New("ErrCmdIllegal") } cli, version, err := LoadMysqlClientByFrom(req.Database) diff --git a/agent/app/service/database_postgresql.go b/agent/app/service/database_postgresql.go index 9bf6eca8c..02c4bacdb 100644 --- a/agent/app/service/database_postgresql.go +++ b/agent/app/service/database_postgresql.go @@ -87,7 +87,7 @@ func (u *PostgresqlService) ListDBOption() ([]dto.PostgresqlOption, error) { } func (u *PostgresqlService) BindUser(req dto.PostgresqlBindUser) error { - if cmd.CheckIllegal(req.Name, req.Username, req.Password) { + if cmd.CheckIllegal(req.Name, req.Username, req.Password) || strings.Contains(req.Password, " ") { return buserr.New("ErrCmdIllegal") } dbItem, err := postgresqlRepo.Get(postgresqlRepo.WithByPostgresqlName(req.Database), repo.WithByName(req.Name)) @@ -123,7 +123,7 @@ func (u *PostgresqlService) BindUser(req dto.PostgresqlBindUser) error { } func (u *PostgresqlService) Create(ctx context.Context, req dto.PostgresqlDBCreate) (*model.DatabasePostgresql, error) { - if cmd.CheckIllegal(req.Name, req.Username, req.Password, req.Format) { + if cmd.CheckIllegal(req.Name, req.Username, req.Password, req.Format) || strings.Contains(req.Password, " ") { return nil, buserr.New("ErrCmdIllegal") } @@ -366,7 +366,7 @@ func (u *PostgresqlService) ChangePrivileges(req dto.PostgresqlPrivileges) error } func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { - if cmd.CheckIllegal(req.Value) { + if cmd.CheckIllegal(req.Value) || strings.Contains(req.Value, " ") { return buserr.New("ErrCmdIllegal") } cli, err := LoadPostgresqlClientByFrom(req.Database) diff --git a/frontend/src/global/form-rules.ts b/frontend/src/global/form-rules.ts index 46ab81cfb..f93c480ce 100644 --- a/frontend/src/global/form-rules.ts +++ b/frontend/src/global/form-rules.ts @@ -151,6 +151,30 @@ const checkIllegal: RuleValidator = (_rule, value, callback) => { } }; +const checkDatabaseUsername: RuleValidator = (_rule, value, callback) => { + if (value && /[&|;'`$()"><\n\r]/.test(value)) { + callback(new Error(i18n.global.t('commons.rule.illegalInput'))); + return; + } + callback(); +}; + +const checkDatabasePassword: RuleValidator = (_rule, value, callback) => { + if (!value) { + callback(); + return; + } + if (value.includes(' ')) { + callback(new Error(i18n.global.t('setting.noSpace'))); + return; + } + if (/[&|;'`$()"><\n\r]/.test(value)) { + callback(new Error(i18n.global.t('commons.rule.illegalInput'))); + return; + } + callback(); +}; + const complexityPassword: RuleValidator = (_rule, value, callback) => { if (value === '' || typeof value === 'undefined' || value == null) { callback(new Error(i18n.global.t('commons.rule.complexityPassword'))); @@ -682,6 +706,8 @@ interface CommonRule { userName: FormItemRule; simpleName: FormItemRule; simplePassword: FormItemRule; + databaseUsername: FormItemRule; + databasePassword: FormItemRule; dbName: FormItemRule; imageName: FormItemRule; composeName: FormItemRule; @@ -860,6 +886,14 @@ export const Rules: CommonRule = { required: true, trigger: 'blur', }, + databaseUsername: { + validator: checkDatabaseUsername, + trigger: 'blur', + }, + databasePassword: { + validator: checkDatabasePassword, + trigger: 'blur', + }, port: { required: true, trigger: 'blur', diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index ac7437150..98335b5db 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -292,7 +292,7 @@ const message = { rePassword: 'Confirm password is inconsistent with the password.', requiredInput: 'This field is required.', requiredSelect: 'Select an item in the list', - illegalChar: 'Injection of characters & ; $ \' ` ( ) " > < | is currently not supported', + illegalChar: "Injection of characters & ; $ ' ` ( ) \" > < {'|'} is currently not supported", illegalInput: "This field mustn't contains illegal characters.", duplicate: 'This value must be unique.', commonName: diff --git a/frontend/src/lang/modules/es-es.ts b/frontend/src/lang/modules/es-es.ts index 6675901e8..51c2169ea 100644 --- a/frontend/src/lang/modules/es-es.ts +++ b/frontend/src/lang/modules/es-es.ts @@ -291,7 +291,7 @@ const message = { rePassword: 'La confirmación de la contraseña no coincide con la contraseña.', requiredInput: 'Este campo es obligatorio.', requiredSelect: 'Seleccione un elemento de la lista', - illegalChar: 'Actualmente no se admite la inyección de caracteres & ; $ \' ` ( ) " > < |', + illegalChar: "Actualmente no se admite la inyección de caracteres & ; $ ' ` ( ) \" > < {'|'}", illegalInput: 'Este campo no debe contener caracteres no permitidos.', duplicate: 'Este valor debe ser único.', commonName: diff --git a/frontend/src/lang/modules/fa.ts b/frontend/src/lang/modules/fa.ts index d853a243a..da67a9e25 100644 --- a/frontend/src/lang/modules/fa.ts +++ b/frontend/src/lang/modules/fa.ts @@ -291,7 +291,7 @@ const message = { rePassword: 'تکرار رمز عبور با رمز عبور مطابقت ندارد.', requiredInput: 'این فیلد الزامی است.', requiredSelect: 'یک مورد از لیست انتخاب کنید', - illegalChar: 'کاراکترهای & ; $ \' ` ( ) " > < | در حال حاضر پشتیبانی نمی‌شوند', + illegalChar: "کاراکترهای & ; $ ' ` ( ) \" > < {'|'} در حال حاضر پشتیبانی نمی‌شوند", illegalInput: 'این فیلد نباید شامل کاراکترهای غیرمجاز باشد.', duplicate: 'این مقدار باید یکتا باشد.', commonName: diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 0c6575c30..694729045 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -292,7 +292,7 @@ const message = { rePassword: 'パスワードがパスワードと矛盾することを確認してください。', requiredInput: 'この項目は必須です。', requiredSelect: 'リスト内のアイテムを選択します', - illegalChar: '現在、文字 & ; $ \' ` ( ) " > < | の注入はサポートされていません', + illegalChar: "現在、文字 & ; $ ' ` ( ) \" > < {'|'} の注入はサポートされていません", illegalInput: 'このフィールドには違法なキャラクターが含まれてはなりません。', duplicate: 'この値は一意である必要があります。', commonName: diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index c3acb73ed..c58c88b41 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -290,7 +290,7 @@ const message = { rePassword: '확인 비밀번호가 비밀번호와 일치하지 않습니다.', requiredInput: '이 필드는 필수 항목입니다.', requiredSelect: '목록에서 항목을 선택하세요', - illegalChar: '현재 & ; $ \' ` ( ) " > < | 문자 주입은 지원되지 않습니다', + illegalChar: "현재 & ; $ ' ` ( ) \" > < {'|'} 문자 주입은 지원되지 않습니다", illegalInput: '이 필드에는 유효하지 않은 문자가 포함될 수 없습니다.', duplicate: '이 값은 고유해야 합니다.', commonName: diff --git a/frontend/src/lang/modules/lo.ts b/frontend/src/lang/modules/lo.ts index d4615b10f..2f045f6e3 100644 --- a/frontend/src/lang/modules/lo.ts +++ b/frontend/src/lang/modules/lo.ts @@ -288,7 +288,7 @@ const message = { rePassword: 'ຢືນຢັນລະຫັດຜ່ານບໍ່ກົງກັນ.', requiredInput: 'ຈຳເປັນຕ້ອງປ້ອນຂໍ້ມູນນີ້.', requiredSelect: 'ເລືອກລາຍການໃນລາຍຊື່', - illegalChar: 'ບໍ່ຮອງຮັບການໃຊ້ຕົວອັກສອນ & ; $ \' ` ( ) " > < | ໃນເວລານີ້', + illegalChar: "ບໍ່ຮອງຮັບການໃຊ້ຕົວອັກສອນ & ; $ ' ` ( ) \" > < {'|'} ໃນເວລານີ້", illegalInput: 'ຂໍ້ມູນນີ້ຕ້ອງບໍ່ມີຕົວອັກສອນທີ່ບໍ່ຖືກຕ້ອງ.', duplicate: 'ຄ່ານີ້ຕ້ອງບໍ່ຊ້ຳກັນ.', commonName: diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index a5d3ac751..2411ca28c 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -295,7 +295,7 @@ const message = { rePassword: 'Pengesahan kata laluan tidak sepadan dengan kata laluan.', requiredInput: 'Ruangan ini wajib diisi.', requiredSelect: 'Pilih satu item dalam senarai', - illegalChar: 'Suntikan aksara & ; $ \' ` ( ) " > < | tidak disokong buat masa ini', + illegalChar: "Suntikan aksara & ; $ ' ` ( ) \" > < {'|'} tidak disokong buat masa ini", illegalInput: 'Ruangan ini tidak boleh mengandungi aksara tidak sah.', duplicate: 'Nilai ini mesti unik.', commonName: diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index 82819f134..0610556c5 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -292,7 +292,7 @@ const message = { rePassword: 'A confirmação da senha não corresponde à senha.', requiredInput: 'Este campo é obrigatório.', requiredSelect: 'Selecione um item na lista', - illegalChar: 'Atualmente não há suporte para injeção dos caracteres & ; $ \' ` ( ) " > < |', + illegalChar: "Atualmente não há suporte para injeção dos caracteres & ; $ ' ` ( ) \" > < {'|'}", illegalInput: 'Este campo não deve conter caracteres ilegais.', duplicate: 'Este valor deve ser único.', commonName: diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index 995f879bd..f43f5b672 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -293,7 +293,7 @@ const message = { rePassword: 'Подтверждение пароля не совпадает с паролем.', requiredInput: 'Это поле обязательно для заполнения.', requiredSelect: 'Выберите элемент из списка', - illegalChar: 'В настоящее время не поддерживается вставка символов & ; $ \' ` ( ) " > < |', + illegalChar: "В настоящее время не поддерживается вставка символов & ; $ ' ` ( ) \" > < {'|'}", illegalInput: 'Это поле не должно содержать недопустимых символов.', duplicate: 'Значение должно быть уникальным.', commonName: diff --git a/frontend/src/lang/modules/tr.ts b/frontend/src/lang/modules/tr.ts index 4a1d5546b..521328ea2 100644 --- a/frontend/src/lang/modules/tr.ts +++ b/frontend/src/lang/modules/tr.ts @@ -295,7 +295,7 @@ const message = { rePassword: 'Şifre onayı, şifre ile tutarsız.', requiredInput: 'Bu alan gereklidir.', requiredSelect: 'Listeden bir öğe seçin', - illegalChar: '& ; $ ` ( ) " > < | karakterlerinin enjekte edilmesi şu anda desteklenmiyor', + illegalChar: "& ; $ ' ` ( ) \" > < {'|'} karakterlerinin enjekte edilmesi şu anda desteklenmiyor", illegalInput: 'Bu alan yasadışı karakterler içermemelidir.', duplicate: 'Bu değer benzersiz olmalıdır.', commonName: diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index 068c22611..ac9c3c350 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -284,7 +284,7 @@ const message = { rePassword: '密碼不一致,請檢查後重新輸入', requiredInput: '請填寫必填項', requiredSelect: '請選擇必選項', - illegalChar: '暫不支援注入字元 & ; $ \' ` ( ) " > < |', + illegalChar: "暫不支援注入字元 & ; $ ' ` ( ) \" > < {'|'}", illegalInput: '輸入框中存在不合法字元', commonName: '支援非特殊字元開頭,英文、中文、數字、.-和_,長度1-128', userName: '支援非特殊字元開頭、英文、中文、數字和_,長度3-30', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 94a9afa0d..9b957e6a1 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -284,7 +284,7 @@ const message = { rePassword: '密码不一致,请检查后重新输入', requiredInput: '请填写必填项', requiredSelect: '请选择必选项', - illegalChar: '暂不支持注入字符 & ; $ \' ` ( ) " > < |', + illegalChar: "暂不支持注入字符 & ; $ ' ` ( ) \" > < {'|'}", illegalInput: '输入框中存在不合法字符', duplicate: '内容不能重复', commonName: '支持非特殊字符开头,英文、中文、数字、.-和_,长度1-128', diff --git a/frontend/src/views/database/mongodb/bind/index.vue b/frontend/src/views/database/mongodb/bind/index.vue index dc6e38da0..41dc81607 100644 --- a/frontend/src/views/database/mongodb/bind/index.vue +++ b/frontend/src/views/database/mongodb/bind/index.vue @@ -50,7 +50,7 @@ const form = reactive({ const rules = reactive({ username: [Rules.requiredInput, Rules.name], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); interface DialogProps { diff --git a/frontend/src/views/database/mongodb/conn/index.vue b/frontend/src/views/database/mongodb/conn/index.vue index cd5020667..db7ade7d7 100644 --- a/frontend/src/views/database/mongodb/conn/index.vue +++ b/frontend/src/views/database/mongodb/conn/index.vue @@ -162,7 +162,7 @@ const form = reactive({ }); const rules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); type FormInstance = InstanceType; diff --git a/frontend/src/views/database/mongodb/index.vue b/frontend/src/views/database/mongodb/index.vue index e75e7dae5..f6be96cff 100644 --- a/frontend/src/views/database/mongodb/index.vue +++ b/frontend/src/views/database/mongodb/index.vue @@ -263,6 +263,7 @@ {{ $t('commons.button.random') }} + {{ $t('commons.rule.illegalChar') }} @@ -418,7 +419,7 @@ const createForm = reactive({ const rules = reactive({ name: [Rules.requiredInput, Rules.dbName], username: [Rules.requiredInput, Rules.name], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], permission: [Rules.requiredSelect], }); diff --git a/frontend/src/views/database/mongodb/password/index.vue b/frontend/src/views/database/mongodb/password/index.vue index dd5c2f96e..34694367b 100644 --- a/frontend/src/views/database/mongodb/password/index.vue +++ b/frontend/src/views/database/mongodb/password/index.vue @@ -49,7 +49,7 @@ const form = reactive({ }); const rules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); interface DialogProps { diff --git a/frontend/src/views/database/mongodb/remote/operate/index.vue b/frontend/src/views/database/mongodb/remote/operate/index.vue index 2d2f05db3..0f932772d 100644 --- a/frontend/src/views/database/mongodb/remote/operate/index.vue +++ b/frontend/src/views/database/mongodb/remote/operate/index.vue @@ -38,6 +38,7 @@ show-password v-model.trim="dialogData.rowData!.password" /> + {{ $t('commons.rule.illegalChar') }} + {{ $t('commons.rule.illegalChar') }} @@ -214,7 +215,7 @@ const rules = reactive({ username: [Rules.requiredInput, Rules.name], permission: [Rules.requiredSelect], host: [Rules.requiredInput, Rules.noSpace, Rules.illegal, { validator: checkMysqlHosts, trigger: 'blur' }], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); interface DialogProps { diff --git a/frontend/src/views/database/mysql/conn/index.vue b/frontend/src/views/database/mysql/conn/index.vue index cfb2b103f..e603e792a 100644 --- a/frontend/src/views/database/mysql/conn/index.vue +++ b/frontend/src/views/database/mysql/conn/index.vue @@ -161,7 +161,7 @@ const form = reactive({ remoteIP: '', }); const rules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); type FormInstance = InstanceType; diff --git a/frontend/src/views/database/mysql/create/index.vue b/frontend/src/views/database/mysql/create/index.vue index 8d15867c3..2d0b5963e 100644 --- a/frontend/src/views/database/mysql/create/index.vue +++ b/frontend/src/views/database/mysql/create/index.vue @@ -183,7 +183,7 @@ const rules = reactive({ userMode: [Rules.requiredSelect], userKey: [Rules.requiredSelect], username: [Rules.requiredInput, Rules.name], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], permission: [Rules.requiredSelect], permissionIPs: [Rules.requiredInput, Rules.noSpace, Rules.illegal, { validator: checkMysqlHosts, trigger: 'blur' }], }); diff --git a/frontend/src/views/database/mysql/remote/operate/index.vue b/frontend/src/views/database/mysql/remote/operate/index.vue index 136a1f003..40fff3c2e 100644 --- a/frontend/src/views/database/mysql/remote/operate/index.vue +++ b/frontend/src/views/database/mysql/remote/operate/index.vue @@ -48,6 +48,7 @@ show-password v-model.trim="dialogData.rowData!.password" /> + {{ $t('commons.rule.illegalChar') }} @@ -167,8 +168,8 @@ const rules = reactive({ version: [Rules.requiredSelect], address: [Rules.ipV4V6OrDomain], port: [Rules.port], - username: [Rules.requiredInput], - password: [Rules.requiredInput], + username: [Rules.requiredInput, Rules.databaseUsername], + password: [Rules.requiredInput, Rules.databasePassword], timeout: [Rules.number, checkNumberRange(1, 600)], }); diff --git a/frontend/src/views/database/mysql/user/index.vue b/frontend/src/views/database/mysql/user/index.vue index 7a3a59532..405b67df6 100644 --- a/frontend/src/views/database/mysql/user/index.vue +++ b/frontend/src/views/database/mysql/user/index.vue @@ -110,6 +110,7 @@ + {{ $t('commons.rule.illegalChar') }} {{ $t('setting.passwordEmptyTip') }} @@ -146,6 +147,7 @@ + {{ $t('commons.rule.illegalChar') }} {{ $t('database.supplementPasswordHelper') }} @@ -263,27 +265,8 @@ const supplementForm = reactive({ password: '', }); const supplementRules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); -const checkPassword = (_rule: unknown, value: string, callback: (error?: Error) => void) => { - if (!value && userDialogMode.value === 'edit') { - callback(); - return; - } - if (!value) { - callback(new Error(i18n.global.t('commons.rule.requiredInput'))); - return; - } - if (value.indexOf(' ') !== -1) { - callback(new Error(i18n.global.t('setting.noSpace'))); - return; - } - if (/[&|;'`$()><]/.test(value)) { - callback(new Error(i18n.global.t('commons.rule.illegalInput'))); - return; - } - callback(); -}; const checkUserHosts = (_rule: unknown, value: string, callback: (error?: Error) => void) => { const hosts = value.split(',').map((item) => item.trim()); if (hosts.length === 0 || hosts.some((item) => !item)) { @@ -296,12 +279,13 @@ const checkUserHosts = (_rule: unknown, value: string, callback: (error?: Error) } callback(); }; -const userRules = reactive({ +const userRules = computed(() => ({ username: [Rules.requiredInput, Rules.name], permission: [Rules.requiredSelect], host: [Rules.requiredInput, Rules.noSpace, Rules.illegal, { validator: checkUserHosts, trigger: 'blur' }], - password: [{ validator: checkPassword, trigger: 'blur' }], -}); + password: + userDialogMode.value === 'create' ? [Rules.requiredInput, Rules.databasePassword] : [Rules.databasePassword], +})); interface DialogProps { database: string; diff --git a/frontend/src/views/database/postgresql/bind/index.vue b/frontend/src/views/database/postgresql/bind/index.vue index 986f2acb6..62d6ec369 100644 --- a/frontend/src/views/database/postgresql/bind/index.vue +++ b/frontend/src/views/database/postgresql/bind/index.vue @@ -58,7 +58,7 @@ const confirmDialogRef = ref(); const rules = reactive({ username: [Rules.requiredInput, Rules.name], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); interface DialogProps { diff --git a/frontend/src/views/database/postgresql/conn/index.vue b/frontend/src/views/database/postgresql/conn/index.vue index 89c29186f..87dc55694 100644 --- a/frontend/src/views/database/postgresql/conn/index.vue +++ b/frontend/src/views/database/postgresql/conn/index.vue @@ -157,7 +157,7 @@ const form = reactive({ remoteIP: '', }); const rules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); type FormInstance = InstanceType; diff --git a/frontend/src/views/database/postgresql/create/index.vue b/frontend/src/views/database/postgresql/create/index.vue index ac542959f..129ee6baf 100644 --- a/frontend/src/views/database/postgresql/create/index.vue +++ b/frontend/src/views/database/postgresql/create/index.vue @@ -66,7 +66,7 @@ const form = reactive({ const rules = reactive({ name: [Rules.requiredInput, Rules.dbName], username: [Rules.requiredInput, Rules.name], - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); type FormInstance = InstanceType; diff --git a/frontend/src/views/database/postgresql/password/index.vue b/frontend/src/views/database/postgresql/password/index.vue index 76eeda341..49118817e 100644 --- a/frontend/src/views/database/postgresql/password/index.vue +++ b/frontend/src/views/database/postgresql/password/index.vue @@ -59,7 +59,7 @@ const changeForm = reactive({ }); const confirmDialogRef = ref(); const rules = reactive({ - password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], + password: [Rules.requiredInput, Rules.databasePassword], }); interface DialogProps { diff --git a/frontend/src/views/database/postgresql/remote/operate/index.vue b/frontend/src/views/database/postgresql/remote/operate/index.vue index fc1e9dc2c..3dc561a17 100644 --- a/frontend/src/views/database/postgresql/remote/operate/index.vue +++ b/frontend/src/views/database/postgresql/remote/operate/index.vue @@ -41,6 +41,7 @@ show-password v-model.trim="dialogData.rowData!.password" /> + {{ $t('commons.rule.illegalChar') }} @@ -111,8 +112,8 @@ const rules = reactive({ version: [Rules.requiredSelect], address: [Rules.ipV4V6OrDomain], port: [Rules.port], - username: [Rules.requiredInput], - password: [Rules.requiredInput], + username: [Rules.requiredInput, Rules.databaseUsername], + password: [Rules.requiredInput, Rules.databasePassword], clientKey: [Rules.requiredInput], clientCert: [Rules.requiredInput],