From 2e6cd26cecb7e2ea53db8aefa840f5a04bcfc0d1 Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Wed, 23 Nov 2022 05:09:54 +0800 Subject: [PATCH] fix: domain name validation hopefully --- cmds/dig.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmds/dig.go b/cmds/dig.go index e61c1ab..c168b56 100644 --- a/cmds/dig.go +++ b/cmds/dig.go @@ -12,6 +12,7 @@ import ( "time" "github.com/go-errors/errors" + "golang.org/x/net/idna" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/utils" ) @@ -27,7 +28,7 @@ var ( digErrInvalidArgs = fmt.Errorf("invalid request") - digDnsNameRe = regexp.MustCompile(`^([a-z0-9_-]+\.?)+|\.$`) + digIdnaMapper = idna.New(idna.MapForLookup(), idna.StrictDomainName(false)) ) type DigRequest struct { @@ -61,8 +62,8 @@ func NewDigRequest(req string) (*DigRequest, error) { return ret, nil } - name := strings.ToLower(args[0]) - if !digDnsNameRe.Match([]byte(name)) { + name, err := digIdnaMapper.ToASCII(args[0]) + if err != nil { return nil, digErrInvalidArgs } ret.Name = name