Skip to content

Commit

Permalink
Fix the last dot in domain match
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Feb 23, 2020
1 parent 5d1827b commit bcc6d7c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 8 additions & 6 deletions conf/dynamic_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ var dynamicMu = sync.Mutex{}

// ShouldProxy check if the domain shoule request though proxy
func ShouldProxy(domain string) bool {
// break deadlook, for wildcard
if strings.Count(domain, ".") > 4 {
return false
}
domain = strings.TrimSuffix(domain, ".")

if domain == Client.Address {
return true
return false
}
if Client.Router.directRules.Match(domain) {
return false
Expand All @@ -43,11 +49,7 @@ func ShouldProxy(domain string) bool {
}

func (d *dynamic) Get(key interface{}) (err error) {
// break deadloop, for ugly wildcard setting dns setting
domain := strings.TrimSuffix(key.(string), ".")
if strings.Count(domain, ".") > 10 {
return nil
}
domain := key.(string)
domainUnderscore := strings.ReplaceAll(domain, ".", "_")
var score int

Expand Down
7 changes: 6 additions & 1 deletion internal/http/tgt_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ func (c *conn) Write(b []byte) (n int, err error) {
return 0, err
}

n, err := c.Conn.Write(append(c.domain, b...))
switch c.typ {
case TGT_OTHER:
n, err = c.Conn.Write(append(c.domain, b...))
default:
n, err = c.Conn.Write(b)
}
return n - len(c.domain), err
}

Expand Down
3 changes: 2 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ func StartServer(relayTarget, password, certFile, keyFile, email string) {
}

go func(conn net.Conn) {
defer conn.Close()

conn, domain, port, err := _http.ParseAddr(conn, passwordData)
if err != nil {
log.Errorw("parse relay target", "err", err)
return
}
defer conn.Close()

addr := relayTarget
if domain != "" {
Expand Down

0 comments on commit bcc6d7c

Please sign in to comment.