feat(core): improve CNAME binding logic with CAS and update hostname validation

This commit is contained in:
ExplodingDragon
2026-02-01 00:49:08 +08:00
parent b4c0ae11df
commit 57e07b3825
7 changed files with 123 additions and 16 deletions

View File

@@ -201,7 +201,7 @@ func (s *ServerMeta) parsePageConfig(ctx context.Context, meta *PageMetaContent,
cname, err := vfs.ReadString(ctx, "CNAME")
if cname != "" && err == nil {
cname = strings.TrimSpace(cname)
if al, ok := s.aliasCheck(cname); ok {
if al, ok := s.AliasCheck(cname); ok {
alias = append(alias, al)
} else {
return fmt.Errorf("invalid alias %s", cname)
@@ -233,7 +233,7 @@ func (s *ServerMeta) parsePageConfig(ctx context.Context, meta *PageMetaContent,
if item == "" {
continue
}
if al, ok := s.aliasCheck(item); ok {
if al, ok := s.AliasCheck(item); ok {
alias = append(alias, al)
} else {
return fmt.Errorf("invalid alias %s", item)
@@ -269,9 +269,9 @@ func (s *ServerMeta) parsePageConfig(ctx context.Context, meta *PageMetaContent,
return nil
}
var regexpHostname = regexp.MustCompile(`^(?:([a-z0-9-]+|\*)\.)?([a-z0-9-]{1,61})\.([a-z0-9]{2,7})$`)
var regexpHostname = regexp.MustCompile(`^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,18}$`)
func (s *ServerMeta) aliasCheck(cname string) (string, bool) {
func (s *ServerMeta) AliasCheck(cname string) (string, bool) {
cname = strings.TrimSpace(cname)
if !regexpHostname.MatchString(cname) {
return "", false