Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 306feb8

Browse files
committed
Really honour blocked addresses
1 parent 38d36a8 commit 306feb8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

commonfilter/commonfilter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func New(next http.Handler, testingLocalhost bool, setters ...optSetter) (*Commo
4949
if err != nil {
5050
log.Errorf("Error enumerating local addresses: %v\n", err)
5151
}
52+
5253
for _, a := range addrs {
5354
str := a.String()
5455
idx := strings.Index(str, "/")
@@ -64,11 +65,15 @@ func New(next http.Handler, testingLocalhost bool, setters ...optSetter) (*Commo
6465

6566
func (f *CommonFilter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
6667
if !f.testingLocalhost && !f.isException(req.URL.Host) {
67-
reqAddr, err := net.ResolveTCPAddr("tcp", req.URL.Host)
68+
reqAddr, err := net.ResolveTCPAddr("tcp", req.Host)
6869

6970
// If there was an error resolving is probably because it wasn't an address
7071
// in the form localhost:port
7172
if err == nil {
73+
if reqAddr.IP.IsLoopback() {
74+
f.errHandler.ServeHTTP(w, req, err)
75+
return
76+
}
7277
for _, ip := range f.localIPs {
7378
if reqAddr.IP.Equal(ip) {
7479
f.errHandler.ServeHTTP(w, req, err)

0 commit comments

Comments
 (0)