mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-27 09:42:16 +00:00
* Add DenyLists parsing * Remove unneeded returned error * Plug global denylist into Command * app creation: apply denylist to backchannel logout URI * Inject denylist to backchannel logout worker * webhook config: validate against blocked URLs * Add notificationsWebhook denylist target * command: Add SMTP endpoint validation against blocklist * command: Add SMS endpoint validation against blocklist * Validate webhook endpoint against denylist on channel notification * Remove unused tests * handle deprecated denylists * remove unintended denylist entry in deprecated list * use single http client * fix tests * update comments * fixes * cleanup * address comments * fix merge --------- Co-authored-by: Livio Spring <[email protected]>
38 lines
927 B
Go
38 lines
927 B
Go
package denylist
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
// NewHTTPTransport returns a cloned default transport that enforces denylist checks
|
|
// right before each TCP dial to avoid DNS rebinding TOCTOU gaps.
|
|
func NewHTTPTransport(denyList []AddressChecker) http.RoundTripper {
|
|
base := http.DefaultTransport.(*http.Transport).Clone()
|
|
if len(denyList) == 0 {
|
|
return base
|
|
}
|
|
dialer := &net.Dialer{
|
|
Timeout: 5 * time.Second,
|
|
KeepAlive: 30 * time.Second,
|
|
Control: func(network, address string, c syscall.RawConn) error {
|
|
host, _, err := net.SplitHostPort(address)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
parsedIP := net.ParseIP(host)
|
|
if parsedIP == nil { // at this point, it must be an IP so it should never happen
|
|
return &net.DNSError{Err: "invalid IP address", Name: host}
|
|
}
|
|
|
|
return IsHostBlocked(denyList, host, parsedIP)
|
|
},
|
|
}
|
|
base.DialContext = dialer.DialContext
|
|
|
|
return base
|
|
}
|