Open platform to collect and prioritize feedback
fix(oauth): block SSRF via custom provider Token/Profile URLs
Matt Roberts10cd0c2e932d
diff --git a/app/services/oauth/oauth.go b/app/services/oauth/oauth.goindex b9e118f96..2e8bab0c4 100644--- a/app/services/oauth/oauth.go+++ b/app/services/oauth/oauth.go@@ -315,6 +315,11 @@ func getOAuthRawProfile(ctx context.Context, q *query.GetOAuthRawProfile) errorreturn err}+ // Guard against SSRF: TokenURL triggers a server-side request during the token exchange.+ if msgs := validate.WebhookURL(config.TokenURL); len(msgs) > 0 {+ return errors.New("Token URL is not allowed: %s", strings.Join(msgs, "; "))+ }+oauthBaseURL := web.OAuthBaseURL(ctx)exchange := (&oauth2.Config{ClientID: config.ClientID,@@ -342,6 +347,11 @@ func getOAuthRawProfile(ctx context.Context, q *query.GetOAuthRawProfile) errorreturn nil}+ // Guard against SSRF: ProfileURL is user-configurable and fetched server-side.+ if msgs := validate.WebhookURL(config.ProfileURL); len(msgs) > 0 {+ return errors.New("Profile URL is not allowed: %s", strings.Join(msgs, "; "))+ }+req := &cmd.HTTPRequest{URL: config.ProfileURL,Method: "GET",diff --git a/app/services/oauth/oauth_test.go b/app/services/oauth/oauth_test.goindex 16b018846..a794c79cb 100644--- a/app/services/oauth/oauth_test.go+++ b/app/services/oauth/oauth_test.go@@ -668,3 +668,31 @@ func TestParseOAuthRawProfile_InvalidInputs(t *testing.T) {})}}++func TestGetOAuthRawProfile_BlocksInternalTokenURL(t *testing.T) {+ RegisterT(t)+ bus.Init(&oauth.Service{})++ // Custom provider whose TokenURL targets an internal/link-local address.+ bus.AddHandler(func(ctx context.Context, q *query.GetCustomOAuthConfigByProvider) error {+ q.Result = &entity.OAuthConfig{+ Provider: q.Provider,+ Status: enum.OAuthConfigEnabled,+ ClientID: "client",+ ClientSecret: "secret",+ AuthorizeURL: "https://example.org/authorize",+ TokenURL: "http://169.254.169.254/latest/api/token",+ ProfileURL: "https://example.org/profile",+ JSONUserIDPath: "id",+ }+ return nil+ })++ ctx := newGetContext("http://login.test.fider.io:3000")+ rawProfile := &query.GetOAuthRawProfile{Provider: "_test1", Code: "any-code"}++ // The SSRF guard must reject before any server-side request (no token exchange happens).+ err := bus.Dispatch(ctx, rawProfile)+ Expect(err).IsNotNil()+ Expect(rawProfile.Result).Equals("")+}