mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-11 04:32:29 +02:00
TestServer, AllowNetworks -> http.Transport
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
)
|
||||
|
||||
@@ -20,29 +17,3 @@ func VerifySourceURL(imageURL string) error {
|
||||
|
||||
return newSourceURLError(imageURL)
|
||||
}
|
||||
|
||||
func VerifySourceNetwork(addr string) error {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
host = addr
|
||||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
return newSourceAddressError(fmt.Sprintf("Invalid source address: %s", addr))
|
||||
}
|
||||
|
||||
if !config.AllowLoopbackSourceAddresses && (ip.IsLoopback() || ip.IsUnspecified()) {
|
||||
return newSourceAddressError(fmt.Sprintf("Loopback source address is not allowed: %s", addr))
|
||||
}
|
||||
|
||||
if !config.AllowLinkLocalSourceAddresses && (ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast()) {
|
||||
return newSourceAddressError(fmt.Sprintf("Link-local source address is not allowed: %s", addr))
|
||||
}
|
||||
|
||||
if !config.AllowPrivateSourceAddresses && ip.IsPrivate() {
|
||||
return newSourceAddressError(fmt.Sprintf("Private source address is not allowed: %s", addr))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user