mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-06-14 13:55:13 +02:00
Allow allowing/blocks hosts by IP range (#236)
This commit is contained in:
parent
3c7d08f311
commit
f91e9cb508
3 changed files with 16 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -324,6 +325,16 @@ func hostMatches(hosts []string, u *url.URL) bool {
|
|||
if strings.HasPrefix(host, "*.") && strings.HasSuffix(u.Host, host[2:]) {
|
||||
return true
|
||||
}
|
||||
// Checks whether the host in u is an IP
|
||||
if ip := net.ParseIP(u.Host); ip != nil {
|
||||
// Checks whether our current host is a CIDR
|
||||
if _, ipnet, err := net.ParseCIDR(host); err == nil {
|
||||
// Checks if our host contains the IP in u
|
||||
if ipnet.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue