Skip to content

Commit 1e95484

Browse files
author
Tim Kendrick
committed
fix: ensure correct SAML Entity ID in client SSO flow
When initiating a SAML client flow via the /sso endpoint, the service provider object Entity ID is omitted from the initialization options, causing the underlying saml library to incorrectly use the metadata URL for the SAML server as the Entity ID. This causes some service providers (e.g. Microsoft Entra ID) to reject the SAML authentication request, as the inferred supabase auth server metadata URL does not match the provider's Entity ID. This change ensures the service provider is correctly initialized with the provider Entity ID during the client auth flow, while retaining the existing behavior for the server metadata endpoint.
1 parent 9a8d0df commit 1e95484

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

internal/api/saml.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// getSAMLServiceProvider generates a new service provider object with the
1515
// (optionally) provided descriptor (metadata) for the identity provider.
16-
func (a *API) getSAMLServiceProvider(identityProvider *saml.EntityDescriptor, idpInitiated bool) *saml.ServiceProvider {
16+
func (a *API) getSAMLServiceProvider(identityProvider *saml.EntityDescriptor, entityID string, idpInitiated bool) *saml.ServiceProvider {
1717
var externalURL *url.URL
1818

1919
if a.config.SAML.ExternalURL != "" {
@@ -47,6 +47,7 @@ func (a *API) getSAMLServiceProvider(identityProvider *saml.EntityDescriptor, id
4747
SignRequest: true,
4848
AllowIDPInitiated: idpInitiated,
4949
IDPMetadata: identityProvider,
50+
EntityID: entityID,
5051
})
5152

5253
provider.AuthnNameIDFormat = saml.PersistentNameIDFormat
@@ -56,7 +57,7 @@ func (a *API) getSAMLServiceProvider(identityProvider *saml.EntityDescriptor, id
5657

5758
// SAMLMetadata serves GoTrue's SAML Service Provider metadata file.
5859
func (a *API) SAMLMetadata(w http.ResponseWriter, r *http.Request) error {
59-
serviceProvider := a.getSAMLServiceProvider(nil, true)
60+
serviceProvider := a.getSAMLServiceProvider(nil, "", true)
6061

6162
metadata := serviceProvider.Metadata()
6263

internal/api/samlacs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (a *API) handleSamlAcs(w http.ResponseWriter, r *http.Request) error {
199199
}
200200
}
201201

202-
serviceProvider := a.getSAMLServiceProvider(idpMetadata, initiatedBy == "idp")
202+
serviceProvider := a.getSAMLServiceProvider(idpMetadata, ssoProvider.SAMLProvider.EntityID, initiatedBy == "idp")
203203
spAssertion, err := serviceProvider.ParseResponse(r, requestIds)
204204
if err != nil {
205205
if ire, ok := err.(*saml.InvalidResponseError); ok {

internal/api/sso.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (a *API) SingleSignOn(w http.ResponseWriter, r *http.Request) error {
9898
return apierrors.NewInternalServerError("Error parsing SAML Metadata for SAML provider").WithInternalError(err)
9999
}
100100

101-
serviceProvider := a.getSAMLServiceProvider(entityDescriptor, false /* <- idpInitiated */)
101+
serviceProvider := a.getSAMLServiceProvider(entityDescriptor, ssoProvider.SAMLProvider.EntityID, false /* <- idpInitiated */)
102102

103103
authnRequest, err := serviceProvider.MakeAuthenticationRequest(
104104
serviceProvider.GetSSOBindingLocation(saml.HTTPRedirectBinding),

0 commit comments

Comments
 (0)