Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复kv敏感信息是token类型时校验错误 --bug=130072281 #3487

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions bcs-services/bcs-bscp/cmd/config-server/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"reflect"
"regexp"
"strings"
"sync"

Expand Down Expand Up @@ -764,36 +763,12 @@ func verifySecretVaule(kit *kit.Kit, secretType, value string) error {
if value == "敏感信息无法导出" {
return errors.New(i18n.T(kit, `please set a password`))
}
switch secretType {
case string(table.SecretTypeCertificate):
if !validateCertificate(value) {
return errors.New(i18n.T(kit, `the certificate format is incorrect, only X.509 format is supported`))
}
case string(table.SecretTypeToken):
if !validateToken(value) {
return errors.New(i18n.T(kit, `the access token format is incorrect. Currently only OAtuh 2.0 and jwt formats
are supported. The length is 32-512 characters, including uppercase and lowercase letters and numbers`))
}
default:
return nil
}

return nil
}

// 验证令牌
func validateToken(token string) bool {
// 令牌长度必须在 32 到 512 个字符之间,并且只包含大小写字母和数字
if len(token) < 32 || len(token) > 512 {
return false
}

matched, err := regexp.MatchString(`^[a-zA-Z0-9]+$`, token)
if err != nil {
return false
if secretType == string(table.SecretTypeCertificate) && !validateCertificate(value) {
return errors.New(i18n.T(kit, `the certificate format is incorrect, only X.509 format is supported`))
}

return matched
return nil
}

// 验证证书
Expand Down
Loading