@@ -29,17 +29,19 @@ func init() {
29
29
}
30
30
}
31
31
32
- func blocksContain (blocks []* net.IPNet , ip net.IP ) bool {
32
+ func blocksContainsAny (blocks []* net.IPNet , ips [] net.IP ) bool {
33
33
for _ , block := range blocks {
34
- if block .Contains (ip ) {
35
- return true
34
+ for _ , ip := range ips {
35
+ if block .Contains (ip ) {
36
+ return true
37
+ }
36
38
}
37
39
}
38
40
return false
39
41
}
40
42
41
- func isPrivateIP ( ip net.IP ) bool {
42
- return blocksContain (privateIPBlocks , ip )
43
+ func containsPrivateIP ( ips [] net.IP ) bool {
44
+ return blocksContainsAny (privateIPBlocks , ips )
43
45
}
44
46
45
47
type noLocalTransport struct {
@@ -59,18 +61,19 @@ func (no noLocalTransport) RoundTrip(req *http.Request) (*http.Response, error)
59
61
no .errlog .WithError (err ).Error ("Cancelled request due to error in address parsing" )
60
62
return
61
63
}
62
- ip := net .ParseIP (host )
63
- if ip == nil {
64
+
65
+ ips , err := net .LookupIP (host )
66
+ if err != nil || len (ips ) == 0 {
64
67
cancel ()
65
- no .errlog .WithError (err ).Error ("Cancelled request due to error in ip parsing " )
68
+ no .errlog .WithError (err ).Error ("Cancelled request due to error in host lookup " )
66
69
return
67
70
}
68
71
69
- if blocksContain (no .allowedBlocks , ip ) {
72
+ if blocksContainsAny (no .allowedBlocks , ips ) {
70
73
return
71
74
}
72
75
73
- if isPrivateIP ( ip ) {
76
+ if containsPrivateIP ( ips ) {
74
77
cancel ()
75
78
no .errlog .Error ("Cancelled attempted request to ip in private range" )
76
79
return
0 commit comments