Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(idp): drop Content-Type header on OAuth2 userinfo GET request (#20660)
Chanwool Jo014acc755b53
diff --git a/backend/plugin/idp/oauth2/oauth2.go b/backend/plugin/idp/oauth2/oauth2.goindex f8ddf9727e..8ab87c2c49 100644--- a/backend/plugin/idp/oauth2/oauth2.go+++ b/backend/plugin/idp/oauth2/oauth2.go@@ -92,7 +92,6 @@ func (p *IdentityProvider) UserInfo(token string) (*storepb.IdentityProviderUserif err != nil {return nil, nil, errors.Wrap(err, "failed to new http request")}- req.Header.Set("Content-Type", "application/json")req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))resp, err := p.client.Do(req)if err != nil {@@ -106,6 +105,11 @@ func (p *IdentityProvider) UserInfo(token string) (*storepb.IdentityProviderUserreturn nil, nil, errors.Wrap(err, "failed to read response body")}+ if resp.StatusCode != http.StatusOK {+ slog.Error("Unexpected status code from user info endpoint", slog.Int("status", resp.StatusCode), slog.String("body", string(body)))+ return nil, nil, errors.Errorf("user info request failed with status %d", resp.StatusCode)+ }+var claims map[string]anyif err := json.Unmarshal(body, &claims); err != nil {slog.Error("Failed to unmarshal response body", slog.String("token", token), slog.String("body", string(body)), log.BBError(err))diff --git a/backend/plugin/idp/oauth2/oauth2_test.go b/backend/plugin/idp/oauth2/oauth2_test.goindex d61e36f42b..ed288e162b 100644--- a/backend/plugin/idp/oauth2/oauth2_test.go+++ b/backend/plugin/idp/oauth2/oauth2_test.go@@ -98,7 +98,15 @@ func newMockServer(t *testing.T, tls bool, code, accessToken string, userinfo []})require.NoError(t, err)})- mux.HandleFunc("/oauth2/userinfo", func(w http.ResponseWriter, _ *http.Request) {+ mux.HandleFunc("/oauth2/userinfo", func(w http.ResponseWriter, r *http.Request) {+ // Regression guard: a body-less userinfo GET must not declare a request+ // media type. OCI IAM Identity Domains reject such a request with HTTP 415+ // and an empty body, which previously surfaced as a misleading JSON+ // unmarshal error.+ if r.Header.Get("Content-Type") != "" {+ w.WriteHeader(http.StatusUnsupportedMediaType)+ return+ }w.Header().Set("Content-Type", "application/json")_, err := w.Write(userinfo)require.NoError(t, err)@@ -165,6 +173,34 @@ func TestIdentityProvider(t *testing.T) {assert.Equal(t, wantUserInfo, userInfoResult)}+func TestUserInfo_NonOKStatusSurfacesError(t *testing.T) {+ // The user info endpoint returns a non-2xx status with an empty body (e.g.+ // OCI's HTTP 415). The error must surface the status instead of the+ // misleading "unexpected end of JSON input".+ s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {+ w.WriteHeader(http.StatusUnsupportedMediaType)+ }))+ defer s.Close()++ p, err := NewIdentityProvider(+ &storepb.OAuth2IdentityProviderConfig{+ ClientId: "test-client-id",+ ClientSecret: "test-client-secret",+ TokenUrl: fmt.Sprintf("%s/oauth2/token", s.URL),+ UserInfoUrl: fmt.Sprintf("%s/oauth2/userinfo", s.URL),+ FieldMapping: &storepb.FieldMapping{+ Identifier: "sub",+ },+ },+ )+ require.NoError(t, err)++ _, _, err = p.UserInfo("test-access-token")+ require.Error(t, err)+ assert.Contains(t, err.Error(), "415")+ assert.NotContains(t, err.Error(), "unexpected end of JSON input")+}+func TestIdentityProvider_SelfSigned(t *testing.T) {ctx := context.Background()