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(deps): update module github.com/go-jose/go-jose/v4 to v4.1.7 (#21795)
renovate[bot]64cc34ee3253
diff --git a/backend/plugin/idp/wif/jwks.go b/backend/plugin/idp/wif/jwks.goindex 80a10297ae..4cdf77a557 100644--- a/backend/plugin/idp/wif/jwks.go+++ b/backend/plugin/idp/wif/jwks.go@@ -4,6 +4,7 @@ import ("context""encoding/json""fmt"+ "log/slog""net/http""net/url""strings"@@ -12,6 +13,8 @@ import ("github.com/go-jose/go-jose/v4""github.com/pkg/errors"++ "github.com/bytebase/bytebase/backend/common/log")var (@@ -178,10 +181,35 @@ func fetchJWKSFromURL(ctx context.Context, jwksURL string) (*jose.JSONWebKeySet,return nil, errors.Errorf("failed to fetch JWKS: HTTP %d", resp.StatusCode)}- var jwks jose.JSONWebKeySet- if err := json.NewDecoder(resp.Body).Decode(&jwks); err != nil {+ var raw struct {+ Keys []json.RawMessage `json:"keys"`+ }+ if err := json.NewDecoder(resp.Body).Decode(&raw); err != nil {return nil, errors.Wrap(err, "failed to decode JWKS")}- return &jwks, nil+ // Decode one key at a time: go-jose refuses a key whose RSA modulus exceeds+ // jose.MaxRSAModulusBits, and decoding the set in one call would let such a+ // key cost us the rest of it, including the one the token was signed with.+ jwks := &jose.JSONWebKeySet{}+ for i, rawKey := range raw.Keys {+ var key jose.JSONWebKey+ if err := json.Unmarshal(rawKey, &key); err != nil {+ slog.Warn("Skipping a JWKS key go-jose cannot parse",+ slog.String("jwksURL", jwksURL),+ slog.Int("index", i),+ log.BBError(err),+ )+ continue+ }+ jwks.Keys = append(jwks.Keys, key)+ }+ // Dropping every key an issuer published is not the same as it publishing+ // none: erroring keeps the emptied set out of the cache, so a fixed issuer+ // is picked up on the next call rather than after cacheDuration.+ if len(jwks.Keys) == 0 && len(raw.Keys) > 0 {+ return nil, errors.New("failed to decode JWKS: no key could be parsed")+ }++ return jwks, nil}diff --git a/backend/plugin/idp/wif/jwks_test.go b/backend/plugin/idp/wif/jwks_test.goindex 01a0823a3e..0408c723f5 100644--- a/backend/plugin/idp/wif/jwks_test.go+++ b/backend/plugin/idp/wif/jwks_test.go@@ -2,11 +2,15 @@ package wifimport ("context"+ "encoding/base64"+ "fmt""io"+ "math/big""net/http""strings""testing"+ "github.com/go-jose/go-jose/v4""github.com/stretchr/testify/require")@@ -181,6 +185,59 @@ func TestFetchJWKSErrorDoesNotIncludeResponseBody(t *testing.T) {require.NotContains(t, err.Error(), secretBody)}+func TestFetchJWKSKeepsUsableKeysBesideOneItCannotParse(t *testing.T) {+ usable := rsaJWKJSON(t, "usable", 2048)+ oversized := rsaJWKJSON(t, "oversized", jose.MaxRSAModulusBits+1)+ setJWKSHTTPClientForTest(t, roundTripFunc(func(*http.Request) (*http.Response, error) {+ return jsonHTTPResponse(http.StatusOK, `{"keys":[`+oversized+`,`+usable+`]}`), nil+ }))++ jwks, err := FetchJWKS(+ context.Background(),+ "https://issuer.example.com",+ "https://keys.example.com/direct.json",+ )+ require.NoError(t, err)+ require.Len(t, jwks.Keys, 1)+ require.Equal(t, "usable", jwks.Keys[0].KeyID)+ require.Len(t, jwks.Key("usable"), 1)+}++func TestFetchJWKSErrorsWhenNoPublishedKeyParses(t *testing.T) {+ oversized := rsaJWKJSON(t, "oversized", jose.MaxRSAModulusBits+1)+ requestCount := 0+ setJWKSHTTPClientForTest(t, roundTripFunc(func(*http.Request) (*http.Response, error) {+ requestCount+++ return jsonHTTPResponse(http.StatusOK, `{"keys":[`+oversized+`]}`), nil+ }))++ for range 2 {+ _, err := FetchJWKS(+ context.Background(),+ "https://issuer.example.com",+ "https://keys.example.com/direct.json",+ )+ require.Error(t, err)+ }+ // The emptied set must not reach the cache, or a fixed issuer would stay+ // unreachable for cacheDuration.+ require.Equal(t, 2, requestCount)+}++// rsaJWKJSON renders a public RSA JWK whose modulus has the given bit length.+// The modulus is fabricated, not generated: JWK parsing reads only n and e, and+// generating a key above jose.MaxRSAModulusBits would dominate the test.+func rsaJWKJSON(t *testing.T, kid string, modulusBits int) string {+ t.Helper()+ modulus := new(big.Int).SetBit(new(big.Int).Lsh(big.NewInt(1), uint(modulusBits-1)), 0, 1)+ require.Equal(t, modulusBits, modulus.BitLen())+ return fmt.Sprintf(`{"kty":"RSA","kid":%q,"alg":"RS256","use":"sig","n":%q,"e":%q}`,+ kid,+ base64.RawURLEncoding.EncodeToString(modulus.Bytes()),+ base64.RawURLEncoding.EncodeToString(big.NewInt(65537).Bytes()),+ )+}+func setJWKSHTTPClientForTest(t *testing.T, transport http.RoundTripper) {t.Helper()diff --git a/go.mod b/go.modindex 1e4ed8e8fd..2cbddf5db9 100644--- a/go.mod+++ b/go.mod@@ -47,7 +47,7 @@ require (github.com/fsnotify/fsnotify v1.10.1github.com/github/gh-ost v1.1.10github.com/go-ego/gse v1.0.2- github.com/go-jose/go-jose/v4 v4.1.5+ github.com/go-jose/go-jose/v4 v4.1.7github.com/go-ldap/ldap/v3 v3.4.15github.com/go-sql-driver/mysql v1.10.1github.com/golang-jwt/jwt/v5 v5.3.1diff --git a/go.sum b/go.sumindex 694e006fb9..9c171d7b0b 100644--- a/go.sum+++ b/go.sum@@ -421,8 +421,8 @@ github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYgithub.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo=github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=-github.com/go-jose/go-jose/v4 v4.1.5 h1:RjgjO2LOtWOJKUC5wpwY9LR3B3vwVAz6JS2YHfYU6eA=-github.com/go-jose/go-jose/v4 v4.1.5/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=+github.com/go-jose/go-jose/v4 v4.1.7 h1:Nac/98uT5LPkfbiFuYa8ktf62a2VxwQ4xbq1GK8pV5E=+github.com/go-jose/go-jose/v4 v4.1.7/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=github.com/go-ldap/ldap/v3 v3.4.15 h1:eRB4f4Ecn1POL1mO86+uUDlecmyWsdiJwh60bAUS4UY=github.com/go-ldap/ldap/v3 v3.4.15/go.mod h1:jeD0c98EdZQCKKKKe4kTWs5aCf6y+j8KuYsYLznZSQk=