Files
Sebastian UnterschützandClaude Opus 5.5 bc8e934568 refactor: move private address guard into netguard
Checks need the same protection as identity provider requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 01:12:53 +01:00

27 lines
806 B
Go

package sso
import (
"context"
"net"
"net/http"
"time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/netguard"
)
// ErrForbiddenAddress is returned when an IdP resolves to an address the
// client may not contact.
var ErrForbiddenAddress = netguard.ErrForbiddenAddress
// SafeHTTPClient returns a client for talking to customer-configured IdPs.
// Unless allowPrivate is set it refuses to connect to non-public addresses.
func SafeHTTPClient(allowPrivate bool) *http.Client {
d := netguard.Dialer(allowPrivate, 5*time.Second)
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.Proxy = nil
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.DialContext(ctx, network, addr)
}
return &http.Client{Transport: tr, Timeout: 10 * time.Second}
}