Improve performance for ACL (#113)
This also in some sense mitigates DoS attacks by flooding servers with a lot of denied hostnames, which could lead to overloading the DNS services. Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
This commit is contained in:
parent
ec0619230b
commit
02be81e696
1 changed files with 12 additions and 0 deletions
|
|
@ -486,6 +486,18 @@ func (h Handler) dialContextCheckACL(ctx context.Context, network, hostPort stri
|
||||||
fmt.Errorf("port %s is not allowed", port))
|
fmt.Errorf("port %s is not allowed", port))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match:
|
||||||
|
for _, rule := range h.aclRules {
|
||||||
|
if _, ok := rule.(*aclDomainRule); ok {
|
||||||
|
switch rule.tryMatch(nil, host) {
|
||||||
|
case aclDecisionDeny:
|
||||||
|
return nil, caddyhttp.Error(http.StatusForbidden, fmt.Errorf("disallowed host %s", host))
|
||||||
|
case aclDecisionAllow:
|
||||||
|
break match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// in case IP was provided, net.LookupIP will simply return it
|
// in case IP was provided, net.LookupIP will simply return it
|
||||||
IPs, err := net.LookupIP(host)
|
IPs, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue