Open platform to collect and prioritize feedback
Enforce SSRF guard at dial time and block IPv6 transition addresses
Matt Roberts51c7a6d2b057
diff --git a/app/models/cmd/http.go b/app/models/cmd/http.goindex 7d6d2f27a..cc5f4bb0a 100644--- a/app/models/cmd/http.go+++ b/app/models/cmd/http.go@@ -14,6 +14,14 @@ type HTTPRequest struct {Headers map[string]stringBasicAuth *dto.BasicAuth+ // BlockPrivateNetworkTargets makes the request refuse to connect to+ // private/internal network addresses (see netguard.IsBlockedIP). The check+ // runs at dial time on the resolved IP, so it is not bypassable via DNS+ // rebinding. Set it for requests to user-configurable URLs (SSRF risk).+ // Ignored when env.Config.AllowPrivateNetworkTargets is true. Guarded+ // requests do not use HTTP(S)_PROXY.+ BlockPrivateNetworkTargets bool+//OutputResponseBody []byteResponseStatusCode intdiff --git a/app/pkg/netguard/netguard.go b/app/pkg/netguard/netguard.gonew file mode 100644index 000000000..a68d7a859--- /dev/null+++ b/app/pkg/netguard/netguard.go@@ -0,0 +1,186 @@+// Package netguard contains the shared SSRF protection used when Fider makes+// outbound HTTP requests to user-configurable URLs (webhooks, custom OAuth+// token/profile URLs).+//+// There are two layers:+// - validate.WebhookURL performs a friendly preflight check (it resolves the+// hostname and rejects private targets with a readable message).+// - The client returned by NewClient enforces the same IsBlockedIP check at+// dial time, on the exact IP address being connected to. This is the real+// enforcement: it cannot be bypassed by DNS rebinding (a hostname that+// resolves to a public IP during validation and to a private IP when the+// request is made).+package netguard++import (+ "context"+ "errors"+ "fmt"+ "net"+ "net/http"+ "syscall"+ "time"+)++// ErrBlockedAddress is returned when a connection to a private/internal+// network address is attempted through a guarded client.+var ErrBlockedAddress = errors.New("connection to a private or internal network address is not allowed")++func mustParseCIDRs(cidrs ...string) []*net.IPNet {+ nets := make([]*net.IPNet, 0, len(cidrs))+ for _, cidr := range cidrs {+ _, n, err := net.ParseCIDR(cidr)+ if err != nil {+ panic(err)+ }+ nets = append(nets, n)+ }+ return nets+}++var blockedIPv4 = mustParseCIDRs(+ "0.0.0.0/8", // "this" network+ "10.0.0.0/8", // private+ "100.64.0.0/10", // carrier-grade NAT+ "127.0.0.0/8", // loopback+ "169.254.0.0/16", // link-local (incl. cloud metadata 169.254.169.254)+ "172.16.0.0/12", // private+ "192.168.0.0/16", // private+ "198.18.0.0/15", // benchmarking+ "224.0.0.0/4", // multicast+ "240.0.0.0/4", // reserved, incl. broadcast 255.255.255.255+)++var blockedIPv6 = mustParseCIDRs(+ "::/128", // unspecified+ "::1/128", // loopback+ "fc00::/7", // unique local+ "fe80::/10", // link-local+ "ff00::/8", // multicast+ "64:ff9b:1::/48", // NAT64 local-use+)++var (+ nat64Prefix = mustParseCIDRs("64:ff9b::/96")[0]+ sixToFourPrefix = mustParseCIDRs("2002::/16")[0]+ teredoPrefix = mustParseCIDRs("2001::/32")[0]+ ipv4Compatible = mustParseCIDRs("::/96")[0] // deprecated IPv4-compatible IPv6 (::a.b.c.d)+)++// IsBlockedIP reports whether ip belongs to a private, internal, or otherwise+// non-public range that outbound requests to user-configured URLs must not reach.+// IPv6 transition addresses (NAT64, 6to4, Teredo, IPv4-compatible) are+// unwrapped and the embedded IPv4 address is checked as well.+// A nil/invalid IP is treated as blocked.+func IsBlockedIP(ip net.IP) bool {+ if ip == nil {+ return true+ }++ // Covers plain IPv4 and IPv4-mapped IPv6 (::ffff:a.b.c.d).+ if v4 := ip.To4(); v4 != nil {+ for _, n := range blockedIPv4 {+ if n.Contains(v4) {+ return true+ }+ }+ return false+ }++ ip16 := ip.To16()+ if ip16 == nil {+ return true+ }++ for _, n := range blockedIPv6 {+ if n.Contains(ip16) {+ return true+ }+ }++ if embedded := embeddedIPv4(ip16); embedded != nil {+ return IsBlockedIP(embedded)+ }++ return false+}++// embeddedIPv4 extracts the IPv4 address embedded in IPv6 transition+// addresses, or returns nil when ip is not such an address.+func embeddedIPv4(ip net.IP) net.IP {+ switch {+ case nat64Prefix.Contains(ip):+ // 64:ff9b::a.b.c.d+ return net.IPv4(ip[12], ip[13], ip[14], ip[15])+ case sixToFourPrefix.Contains(ip):+ // 2002:AABB:CCDD::/48+ return net.IPv4(ip[2], ip[3], ip[4], ip[5])+ case teredoPrefix.Contains(ip):+ // 2001:0000:<server v4>:<flags>:<port>:<client v4 XOR 0xffffffff>+ return net.IPv4(ip[12]^0xff, ip[13]^0xff, ip[14]^0xff, ip[15]^0xff)+ case ipv4Compatible.Contains(ip):+ // ::a.b.c.d (:: and ::1 are already handled by blockedIPv6)+ return net.IPv4(ip[12], ip[13], ip[14], ip[15])+ }+ return nil+}++// dialControl runs after DNS resolution, immediately before each connect()+// syscall, with the literal IP:port being connected to. It therefore also+// covers every address tried by happy-eyeballs / fallback dialing.+func dialControl(network, address string, _ syscall.RawConn) error {+ host, _, err := net.SplitHostPort(address)+ if err != nil {+ return fmt.Errorf("%w: %s", ErrBlockedAddress, address)+ }+ if IsBlockedIP(net.ParseIP(host)) {+ return fmt.Errorf("%w: %s", ErrBlockedAddress, host)+ }+ return nil+}++// NewClient returns an http.Client that refuses to connect to any address for+// which IsBlockedIP returns true. It mirrors Fider's default client settings:+// 30s timeout and redirects are not followed.+//+// Proxies are intentionally disabled (Proxy: nil, i.e. HTTP(S)_PROXY is+// ignored). With a proxy, the dial would go to the proxy rather than to the+// target, so the dial-time check would inspect the proxy's address and either+// block every request (proxy on a private network) or protect nothing (the+// proxy resolves and connects to the target itself). Guarded requests are+// therefore always sent directly.+func NewClient() *http.Client {+ dialer := &net.Dialer{+ Timeout: 30 * time.Second,+ KeepAlive: 30 * time.Second,+ Control: dialControl,+ }++ var transport *http.Transport+ if t, ok := http.DefaultTransport.(*http.Transport); ok {+ transport = t.Clone()+ } else {+ transport = &http.Transport{+ ForceAttemptHTTP2: true,+ MaxIdleConns: 100,+ IdleConnTimeout: 90 * time.Second,+ TLSHandshakeTimeout: 10 * time.Second,+ ExpectContinueTimeout: 1 * time.Second,+ }+ }+ transport.Proxy = nil+ transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {+ return dialer.DialContext(ctx, network, addr)+ }++ return &http.Client{+ Timeout: 30 * time.Second,+ Transport: transport,+ CheckRedirect: func(req *http.Request, via []*http.Request) error {+ return http.ErrUseLastResponse+ },+ }+}++// Client is a shared guarded client, safe for concurrent use.+var Client = NewClient()diff --git a/app/pkg/netguard/netguard_test.go b/app/pkg/netguard/netguard_test.gonew file mode 100644index 000000000..f95b8a182--- /dev/null+++ b/app/pkg/netguard/netguard_test.go@@ -0,0 +1,128 @@+package netguard_test++import (+ "context"+ "errors"+ "net"+ "net/http"+ "net/http/httptest"+ "testing"++ . "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/netguard"+)++func TestIsBlockedIP(t *testing.T) {+ RegisterT(t)++ testCases := []struct {+ ip string+ blocked bool+ }{+ // IPv4 private / internal+ {"0.0.0.0", true},+ {"0.1.2.3", true},+ {"10.0.0.1", true},+ {"100.64.0.1", true},+ {"100.127.255.255", true},+ {"127.0.0.1", true},+ {"127.255.255.254", true},+ {"169.254.169.254", true},+ {"172.16.0.1", true},+ {"172.31.255.255", true},+ {"192.168.1.1", true},+ {"198.18.0.1", true},+ {"198.19.255.255", true},+ {"224.0.0.1", true},+ {"239.255.255.250", true},+ {"240.0.0.1", true},+ {"255.255.255.255", true},++ // IPv4-mapped IPv6+ {"::ffff:127.0.0.1", true},+ {"::ffff:169.254.169.254", true},+ {"::ffff:8.8.8.8", false},++ // IPv6 private / internal+ {"::", true},+ {"::1", true},+ {"fc00::1", true},+ {"fd12:3456::1", true},+ {"fe80::1", true},+ {"ff02::1", true},+ {"ff0e::1", true},+ {"64:ff9b:1::1", true},++ // NAT64 64:ff9b::/96+ {"64:ff9b::a9fe:a9fe", true},+ {"64:ff9b::7f00:1", true},+ {"64:ff9b::a00:1", true},+ {"64:ff9b::808:808", false},++ // 6to4 2002::/16+ {"2002:a9fe:a9fe::1", true},+ {"2002:7f00:1::1", true},+ {"2002:c0a8:101::1", true},+ {"2002:0808:0808::1", false},++ // Teredo 2001:0000::/32, client IPv4 = last 4 bytes XOR 0xff+ {"2001:0:4136:e378:8000:63bf:80ff:fffe", true}, // client 127.0.0.1+ {"2001:0:4136:e378:8000:63bf:5601:5601", true}, // client 169.254.169.254+ {"2001:0:4136:e378:8000:63bf:f7f7:f7f7", false}, // client 8.8.8.8++ // Deprecated IPv4-compatible+ {"::7f00:1", true},+ {"::a9fe:a9fe", true},++ // Public+ {"8.8.8.8", false},+ {"1.1.1.1", false},+ {"203.0.113.1", false},+ {"100.63.255.255", false},+ {"100.128.0.0", false},+ {"198.20.0.1", false},+ {"2001:4860:4860::8888", false},+ {"2606:4700:4700::1111", false},+ }++ for _, tc := range testCases {+ ip := net.ParseIP(tc.ip)+ if ip == nil {+ t.Fatalf("invalid test IP %s", tc.ip)+ }+ if got := netguard.IsBlockedIP(ip); got != tc.blocked {+ t.Errorf("IsBlockedIP(%s) = %v, expected %v", tc.ip, got, tc.blocked)+ }+ }++ Expect(netguard.IsBlockedIP(nil)).IsTrue()+}++func newLocalServer(t *testing.T) *httptest.Server {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(http.StatusOK)+ }))+ t.Cleanup(server.Close)+ return server+}++func TestClient_RejectsBlockedTargetsAtDialTime(t *testing.T) {+ RegisterT(t)++ server := newLocalServer(t)+ _, port, _ := net.SplitHostPort(server.Listener.Addr().String())++ for _, rawurl := range []string{+ server.URL, // literal 127.0.0.1+ "http://localhost:" + port + "/", // hostname resolving to loopback+ } {+ req, _ := http.NewRequestWithContext(context.Background(), "GET", rawurl, nil)+ res, err := netguard.Client.Do(req)+ if res != nil {+ _ = res.Body.Close()+ }+ if err == nil || !errors.Is(err, netguard.ErrBlockedAddress) {+ t.Errorf("%s: expected ErrBlockedAddress, got %v", rawurl, err)+ }+ }+}diff --git a/app/pkg/validate/general.go b/app/pkg/validate/general.goindex 3a4599f08..f28057cad 100644--- a/app/pkg/validate/general.go+++ b/app/pkg/validate/general.go@@ -10,6 +10,7 @@ import ("github.com/getfider/fider/app/models/query""github.com/getfider/fider/app/pkg/bus""github.com/getfider/fider/app/pkg/i18n"+ "github.com/getfider/fider/app/pkg/netguard""github.com/getfider/fider/app/pkg/env")@@ -17,7 +18,7 @@ import (var emailRegex = regexp.MustCompile("^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$")var hostnameRegex = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)-//Email validates given email address+// Email validates given email addressfunc Email(ctx context.Context, email string) []string {email = strings.ToLower(email)@@ -37,7 +38,7 @@ func Email(ctx context.Context, email string) []string {return []string{}}-//URL validates given URL+// URL validates given URLfunc URL(ctx context.Context, rawurl string) []string {if len(rawurl) > 300 {return []string{i18n.T(ctx, "validation.maxstringlen",@@ -62,6 +63,12 @@ func URL(ctx context.Context, rawurl string) []string {// internal services (e.g. an integration server on a LAN) can relax the network// check by setting ALLOW_PRIVATE_NETWORK_TARGETS=true; format validation (valid URL,// scheme http/https) still applies in that mode.+//+// This is only a preflight check that produces friendly error messages. Because+// the hostname is resolved again when the request is made (DNS rebinding), the+// real enforcement happens at dial time: callers must also set+// cmd.HTTPRequest.BlockPrivateNetworkTargets (or use netguard.Client), which+// applies the same netguard.IsBlockedIP check to the IP actually connected to.func WebhookURL(rawurl string) []string {u, err := url.Parse(rawurl)if err != nil || u.Host == "" {@@ -84,7 +91,7 @@ func WebhookURL(rawurl string) []string {}if ip := net.ParseIP(hostname); ip != nil {- if isBlockedIP(ip) {+ if netguard.IsBlockedIP(ip) {return []string{"This URL is not allowed because it targets a private or internal network address."}}return []string{}@@ -96,7 +103,7 @@ func WebhookURL(rawurl string) []string {}for _, addr := range addrs {- if ip := net.ParseIP(addr); ip != nil && isBlockedIP(ip) {+ if ip := net.ParseIP(addr); ip != nil && netguard.IsBlockedIP(ip) {return []string{"This URL is not allowed because it targets a private or internal network address."}}}@@ -104,15 +111,7 @@ func WebhookURL(rawurl string) []string {return []string{}}-func isBlockedIP(ip net.IP) bool {- return ip.IsLoopback() ||- ip.IsPrivate() ||- ip.IsLinkLocalUnicast() ||- ip.IsLinkLocalMulticast() ||- ip.IsUnspecified()-}--//CNAME validates given cname+// CNAME validates given cnamefunc CNAME(ctx context.Context, cname string) []string {cname = strings.ToLower(cname)diff --git a/app/pkg/validate/general_test.go b/app/pkg/validate/general_test.goindex 461066a5b..4b7b02c06 100644--- a/app/pkg/validate/general_test.go+++ b/app/pkg/validate/general_test.go@@ -92,6 +92,21 @@ func TestWebhookURL_BlockedAddresses(t *testing.T) {"http://169.254.169.254/latest/meta-data/","http://169.254.1.1/hook","http://0.0.0.0/hook",+ "http://100.64.0.1/hook",+ "http://198.18.0.1/hook",+ "http://224.0.0.1/hook",+ "http://255.255.255.255/hook",+ "http://[::ffff:127.0.0.1]/hook",+ "http://[::ffff:169.254.169.254]/hook",+ "http://[fd00::1]/hook",+ "http://[fe80::1]/hook",+ "http://[ff02::1]/hook",+ "http://[64:ff9b::a9fe:a9fe]/latest/meta-data/",+ "http://[64:ff9b::7f00:1]/hook",+ "http://[64:ff9b:1::1]/hook",+ "http://[2002:a9fe:a9fe::1]/hook",+ "http://[2002:7f00:1::1]:8080/hook",+ "http://[2001:0:4136:e378:8000:63bf:80ff:fffe]/hook","ftp://example.com/hook","file:///etc/passwd","gopher://example.com",@@ -109,6 +124,9 @@ func TestWebhookURL_AllowedAddresses(t *testing.T) {"https://discord.com/api/webhooks/123/abc","http://example.com/webhook","https://203.0.113.1/hook",+ "https://[2001:4860:4860::8888]/hook",+ "https://[2002:0808:0808::1]/hook",+ "https://[64:ff9b::808:808]/hook",} {messages := validate.WebhookURL(rawurl)Expect(messages).HasLen(0)diff --git a/app/services/httpclient/httpclient.go b/app/services/httpclient/httpclient.goindex c71e843aa..26fccd829 100644--- a/app/services/httpclient/httpclient.go+++ b/app/services/httpclient/httpclient.go@@ -9,6 +9,7 @@ import ("github.com/getfider/fider/app/models/cmd""github.com/getfider/fider/app/pkg/bus""github.com/getfider/fider/app/pkg/env"+ "github.com/getfider/fider/app/pkg/netguard")func init() {@@ -39,6 +40,17 @@ func (s Service) Init() {bus.AddHandler(requestHandler)}+// clientFor returns the HTTP client to use for the given request. Requests that+// opt in to BlockPrivateNetworkTargets use the netguard client, which rejects+// private/internal addresses at dial time, unless the instance explicitly+// allows private network targets.+func clientFor(c *cmd.HTTPRequest) *http.Client {+ if c.BlockPrivateNetworkTargets && !env.Config.AllowPrivateNetworkTargets {+ return netguard.Client+ }+ return http.DefaultClient+}+func requestHandler(ctx context.Context, c *cmd.HTTPRequest) error {req, err := http.NewRequest(c.Method, c.URL, c.Body)if err != nil {@@ -53,7 +65,7 @@ func requestHandler(ctx context.Context, c *cmd.HTTPRequest) error {req.SetBasicAuth(c.BasicAuth.User, c.BasicAuth.Password)}- res, err := http.DefaultClient.Do(req)+ res, err := clientFor(c).Do(req)if err != nil {return err}diff --git a/app/services/httpclient/httpclient_test.go b/app/services/httpclient/httpclient_test.gonew file mode 100644index 000000000..63dd14e1f--- /dev/null+++ b/app/services/httpclient/httpclient_test.go@@ -0,0 +1,66 @@+package httpclient++import (+ "context"+ "errors"+ "net/http"+ "net/http/httptest"+ "testing"++ "github.com/getfider/fider/app/models/cmd"+ . "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/env"+ "github.com/getfider/fider/app/pkg/netguard"+)++// The httpclient service is disabled under env.IsTest(), so these tests call+// requestHandler directly instead of dispatching through the bus.+func TestRequestHandler_BlockPrivateNetworkTargets(t *testing.T) {+ RegisterT(t)++ original := env.Config.AllowPrivateNetworkTargets+ t.Cleanup(func() { env.Config.AllowPrivateNetworkTargets = original })++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(http.StatusOK)+ _, _ = w.Write([]byte("internal secret"))+ }))+ t.Cleanup(server.Close)++ testCases := []struct {+ name string+ block bool+ allowPrivate bool+ expectBlock bool+ }{+ {"guarded request to loopback is rejected", true, false, true},+ {"unguarded request to loopback succeeds", false, false, false},+ {"guarded request succeeds when private targets are allowed", true, true, false},+ }++ for _, tc := range testCases {+ env.Config.AllowPrivateNetworkTargets = tc.allowPrivate++ req := &cmd.HTTPRequest{+ URL: server.URL,+ Method: "GET",+ BlockPrivateNetworkTargets: tc.block,+ }+ err := requestHandler(context.Background(), req)++ if tc.expectBlock {+ if err == nil || !errors.Is(err, netguard.ErrBlockedAddress) {+ t.Errorf("%s: expected ErrBlockedAddress, got %v", tc.name, err)+ }+ Expect(req.ResponseStatusCode).Equals(0)+ continue+ }++ if err != nil {+ t.Errorf("%s: unexpected error %v", tc.name, err)+ continue+ }+ Expect(req.ResponseStatusCode).Equals(http.StatusOK)+ Expect(string(req.ResponseBody)).Equals("internal secret")+ }+}diff --git a/app/services/oauth/oauth.go b/app/services/oauth/oauth.goindex 95550b930..94026f109 100644--- a/app/services/oauth/oauth.go+++ b/app/services/oauth/oauth.go@@ -20,6 +20,7 @@ import ("github.com/getfider/fider/app/pkg/errors""github.com/getfider/fider/app/pkg/jsonq""github.com/getfider/fider/app/pkg/jwt"+ "github.com/getfider/fider/app/pkg/netguard""github.com/getfider/fider/app/pkg/validate""github.com/getfider/fider/app/pkg/web""golang.org/x/oauth2"@@ -335,7 +336,17 @@ func getOAuthRawProfile(ctx context.Context, q *query.GetOAuthRawProfile) errorRedirectURL: fmt.Sprintf("%s/oauth/%s/callback", oauthBaseURL, q.Provider),}).Exchange- oauthToken, err := exchange(ctx, q.Code)+ // Custom providers have admin-configurable Token/Profile URLs, so enforce the+ // SSRF guard at dial time as well (the WebhookURL preflight above can be+ // bypassed via DNS rebinding). Built-in providers use fixed public URLs and+ // keep the default client (which honours HTTP(S)_PROXY).+ guard := isCustomProvider(config) && !env.Config.AllowPrivateNetworkTargets+ exchangeCtx := ctx+ if guard {+ exchangeCtx = context.WithValue(ctx, oauth2.HTTPClient, netguard.Client)+ }++ oauthToken, err := exchange(exchangeCtx, q.Code)if err != nil {return err}@@ -362,6 +373,7 @@ func getOAuthRawProfile(ctx context.Context, q *query.GetOAuthRawProfile) errorHeaders: map[string]string{"Authorization": "Bearer " + oauthToken.AccessToken,},+ BlockPrivateNetworkTargets: isCustomProvider(config),}if err := bus.Dispatch(ctx, req); err != nil {@@ -433,6 +445,17 @@ func listAllOAuthProviders(ctx context.Context, q *query.ListAllOAuthProviders)return nil}+// isCustomProvider reports whether config is a tenant-defined (custom) OAuth+// provider rather than one of the built-in system providers.+func isCustomProvider(config *entity.OAuthConfig) bool {+ for _, p := range systemProviders {+ if p == config {+ return false+ }+ }+ return true+}+func getConfig(ctx context.Context, provider string) (*entity.OAuthConfig, error) {for _, config := range systemProviders {if config.Status == enum.OAuthConfigEnabled && config.Provider == provider {diff --git a/app/services/webhook/webhook.go b/app/services/webhook/webhook.goindex 634da9355..fff335ec5 100644--- a/app/services/webhook/webhook.go+++ b/app/services/webhook/webhook.go@@ -98,6 +98,9 @@ func triggerWebhook(ctx context.Context, webhook *entity.Webhook, props webhook.Method: webhook.HttpMethod,Headers: webhook.HttpHeaders,BasicAuth: nil,+ // Enforce the SSRF guard at dial time too; the WebhookURL preflight+ // above can be bypassed by DNS rebinding.+ BlockPrivateNetworkTargets: true,}err = bus.Dispatch(ctx, httpRequest)if err != nil {