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: validate LDAP phone before use, matching OAuth2/OIDC
Danny3747f26a5102
diff --git a/backend/plugin/idp/ldap/ldap.go b/backend/plugin/idp/ldap/ldap.goindex b5fd0b45e0..bd4d7cb3c1 100644--- a/backend/plugin/idp/ldap/ldap.go+++ b/backend/plugin/idp/ldap/ldap.go@@ -11,6 +11,7 @@ import ("github.com/go-ldap/ldap/v3""github.com/pkg/errors"+ "github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store")@@ -220,11 +221,20 @@ func (p *IdentityProvider) mappedAttributes() []string {}func (p *IdentityProvider) userInfoFromEntry(entry *ldap.Entry) *storepb.IdentityProviderUserInfo {- return &storepb.IdentityProviderUserInfo{+ userInfo := &storepb.IdentityProviderUserInfo{Identifier: entry.GetAttributeValue(p.config.FieldMapping.Identifier),DisplayName: entry.GetAttributeValue(p.config.FieldMapping.DisplayName),- Phone: entry.GetAttributeValue(p.config.FieldMapping.Phone),}+ // Only set phone if it's valid, matching the OAuth2/OIDC providers. This value+ // is persisted as principal.phone on first sign-in, and the user APIs reject+ // non-E.164 phones, so a raw directory value (local number, extension) must not+ // leak through.+ if phone := entry.GetAttributeValue(p.config.FieldMapping.Phone); phone != "" {+ if err := common.ValidatePhone(phone); err == nil {+ userInfo.Phone = phone+ }+ }+ return userInfo}// entryAttributes flattens an LDAP entry into a display map: multi-valueddiff --git a/backend/plugin/idp/ldap/ldap_test.go b/backend/plugin/idp/ldap/ldap_test.goindex d078ee5081..81c088e965 100644--- a/backend/plugin/idp/ldap/ldap_test.go+++ b/backend/plugin/idp/ldap/ldap_test.go@@ -228,7 +228,7 @@ func TestIdentityProvider(t *testing.T) {testUID = "alice"testDisplayName = "Alice Smith"testMail = "[email protected]"- testPhone = "+1-555-0100"+ testPhone = "+14155550100")host, port := newMockServer(t, testUID, testDisplayName, testMail, testPhone)ldap, err := NewIdentityProvider(@@ -272,6 +272,42 @@ func TestIdentityProvider(t *testing.T) {}, attributes)}+func TestUserInfoFromEntry(t *testing.T) {+ p := &IdentityProvider{+ config: IdentityProviderConfig{+ FieldMapping: &storepb.FieldMapping{+ Identifier: "uid",+ DisplayName: "cn",+ Phone: "telephoneNumber",+ },+ },+ }+ entryWithPhone := func(phone string) *goldap.Entry {+ attributes := []*goldap.EntryAttribute{+ goldap.NewEntryAttribute("uid", []string{"alice"}),+ goldap.NewEntryAttribute("cn", []string{"Alice Smith"}),+ }+ if phone != "" {+ attributes = append(attributes, goldap.NewEntryAttribute("telephoneNumber", []string{phone}))+ }+ return &goldap.Entry{DN: "uid=alice,dc=example,dc=com", Attributes: attributes}+ }++ got := p.userInfoFromEntry(entryWithPhone("+14155550100"))+ assert.Equal(t, "alice", got.Identifier)+ assert.Equal(t, "Alice Smith", got.DisplayName)+ assert.Equal(t, "+14155550100", got.Phone)++ // A raw directory phone that is not a valid E.164 number (local number,+ // fictional range, extension) must be dropped, not persisted as principal.phone.+ for _, invalid := range []string{"+1-555-0199", "555-0199", "x1234"} {+ assert.Emptyf(t, p.userInfoFromEntry(entryWithPhone(invalid)).Phone, "phone %q should be dropped", invalid)+ }++ // No phone attribute present -> empty.+ assert.Empty(t, p.userInfoFromEntry(entryWithPhone("")).Phone)+}+func TestEntryAttributes(t *testing.T) {entry := &goldap.Entry{DN: "uid=alice,ou=Users,dc=example,dc=com",