[MM-14333] Stricten external HTTP Calls to require that own IPs need to be explicitly whitelisted (#10375)

* Stricten external HTTP Calls to require that own IPs need to be explicitly whitelisted

* gofmt

* Documentation; Style fixes for IsOwnIP function
Этот коммит содержится в:
Daniel Schalla
2019-03-01 16:22:24 +01:00
коммит произвёл GitHub
родитель d85dff81a8
Коммит 7ac5715a02
3 изменённых файлов: 88 добавлений и 1 удалений

Просмотреть файл

@@ -67,12 +67,24 @@ func (h *HTTPServiceImpl) MakeTransport(trustURLs bool) http.RoundTripper {
}
allowIP := func(ip net.IP) bool {
if !IsReservedIP(ip) {
reservedIP := IsReservedIP(ip)
ownIP, err := IsOwnIP(ip)
// If there is an error getting the self-assigned IPs, default to the secure option
if err != nil {
return false
}
// If it's not a reserved IP and it's not self-assigned IP, accept the IP
if !reservedIP && !ownIP {
return true
}
if h.configService.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil {
return false
}
// In the case it's the self-assigned IP, enforce that it needs to be explicitly added to the AllowedUntrustedInternalConnections
for _, allowed := range strings.Fields(*h.configService.Config().ServiceSettings.AllowedUntrustedInternalConnections) {
if _, ipRange, err := net.ParseCIDR(allowed); err == nil && ipRange.Contains(ip) {
return true