Merge commit from fork

* 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]>
This commit is contained in:
Marco A.
2026-06-15 15:36:14 +02:00
committed by GitHub
co-authored by Livio Spring
parent d184e976fc
commit 8e82ec1cb9
97 changed files with 1834 additions and 285 deletions
+57 -20
View File
@@ -7,23 +7,25 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/zerrors"
)
func TestIsHostBlocked(t *testing.T) {
func TestIsURLBlocked(t *testing.T) {
t.Parallel()
var denyList = []AddressChecker{
mustNewHostChecker(t, "192.168.5.0/24"),
mustNewHostChecker(t, "127.0.0.1"),
mustNewHostChecker(t, "test.com"),
denyList := []AddressChecker{
NewHostChecker("192.168.5.0/24"),
NewHostChecker("127.0.0.1"),
NewHostChecker("test.com"),
}
type fields struct {
lookup func(host string) ([]net.IP, error)
}
type args struct {
address *url.URL
}
tests := []struct {
name string
fields fields
@@ -31,21 +33,31 @@ func TestIsHostBlocked(t *testing.T) {
want error
}{
{
name: "in range",
name: "in range (CIDR match)",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP("192.168.5.4")}, nil
},
},
args: args{
address: mustNewURL(t, "https://192.168.5.4/hodor"),
},
want: NewAddressDeniedError("192.168.5.0/24"),
},
{
name: "exact ip",
name: "exact ip literal match",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP("127.0.0.1")}, nil
},
},
args: args{
address: mustNewURL(t, "http://127.0.0.1:8080/hodor"),
},
want: NewAddressDeniedError("127.0.0.1"),
},
{
name: "address match",
name: "domain string match",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP("194.264.52.4")}, nil
@@ -57,7 +69,7 @@ func TestIsHostBlocked(t *testing.T) {
want: NewAddressDeniedError("test.com"),
},
{
name: "address not match",
name: "allowed domain string pass",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP("194.264.52.4")}, nil
@@ -69,7 +81,7 @@ func TestIsHostBlocked(t *testing.T) {
want: nil,
},
{
name: "looked up ip matches",
name: "unmatched domain resolves to blocked IP (SSRF pivot attempt)",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP("127.0.0.1")}, nil
@@ -81,7 +93,7 @@ func TestIsHostBlocked(t *testing.T) {
want: NewAddressDeniedError("127.0.0.1"),
},
{
name: "lookup failure",
name: "dns resolver failures are isolated",
fields: fields{
lookup: func(host string) ([]net.IP, error) {
return nil, io.EOF
@@ -93,23 +105,48 @@ func TestIsHostBlocked(t *testing.T) {
want: zerrors.ThrowInternal(io.EOF, "NET-4m9s2", "lookup failed"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := IsHostBlocked(denyList, tt.args.address, tt.fields.lookup)
got := IsURLBlocked(denyList, tt.args.address, tt.fields.lookup)
assert.ErrorIs(t, got, tt.want)
})
}
}
func mustNewHostChecker(t *testing.T, ip string) AddressChecker {
t.Helper()
checker, err := NewHostChecker(ip)
if err != nil {
t.Errorf("unable to parse cidr of %q because: %v", ip, err)
t.FailNow()
func TestIsHostnameBlocked_EdgeCases(t *testing.T) {
t.Parallel()
denyList := []AddressChecker{
NewHostChecker("127.0.0.1"),
NewHostChecker("blocked.example.com"),
}
return checker
t.Run("blocked by host lookup via hostname method", func(t *testing.T) {
t.Parallel()
err := IsHostnameBlocked(denyList, "safe.example.com", func(_ string) ([]net.IP, error) {
return []net.IP{net.ParseIP("127.0.0.1")}, nil
})
assert.ErrorIs(t, err, NewAddressDeniedError("127.0.0.1"))
})
t.Run("blocked by exact domain string mapping", func(t *testing.T) {
t.Parallel()
err := IsHostnameBlocked(denyList, "blocked.example.com", func(_ string) ([]net.IP, error) {
return []net.IP{net.ParseIP("192.0.2.1")}, nil
})
assert.ErrorIs(t, err, NewAddressDeniedError("blocked.example.com"))
})
t.Run("ipv6 target check compatibility", func(t *testing.T) {
t.Parallel()
// URL parsing or raw string handling yields plain IPv6 targets, make sure checker behaves cleanly
err := IsHostnameBlocked(denyList, "::1", func(_ string) ([]net.IP, error) {
return []net.IP{net.ParseIP("::1")}, nil
})
assert.NoError(t, err)
})
}
func mustNewURL(t *testing.T, raw string) *url.URL {