feat(sso): add openid connect client with pkce and guarded discovery

Issuer URLs come from customers, so requests to their IdPs refuse
non-public addresses unless private networks are explicitly allowed.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:30:43 +01:00
1 parent d1976ed57a
commit 9ad5f29f1b
7 files changed
+576 -19

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package sso
import (
"errors"
"net/http"
"net/http/httptest"
"net/netip"
"testing"
)
func TestIsPublic(t *testing.T) {
tests := map[string]bool{
"8.8.8.8": true,
"2606:4700::1111": true,
"127.0.0.1": false,
"10.1.2.3": false,
"172.16.0.1": false,
"192.168.1.1": false,
"169.254.169.254": false,
"100.64.0.1": false,
"0.0.0.0": false,
"::1": false,
"fd00::1": false,
"fe80::1": false,
"::ffff:127.0.0.1": false,
}
for addr, want := range tests {
if got := isPublic(netip.MustParseAddr(addr)); got != want {
t.Errorf("isPublic(%s) = %t, want %t", addr, got, want)
}
}
}
func TestSafeHTTPClientBlocksLoopback(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
defer srv.Close()
if _, err := SafeHTTPClient(false).Get(srv.URL); !errors.Is(err, ErrForbiddenAddress) {
t.Errorf("Get(%s) with private networks denied: error = %v, want %v", srv.URL, err, ErrForbiddenAddress)
}
resp, err := SafeHTTPClient(true).Get(srv.URL)
if err != nil {
t.Fatalf("Get(%s) with private networks allowed failed: %v", srv.URL, err)
}
_ = resp.Body.Close()
}