Skip to content

fix: validate SAML metadata before updating it in the login flow - #2704

Open
cstockton wants to merge 1 commit into
masterfrom
cs/sso-login-validation
Open

fix: validate SAML metadata before updating it in the login flow#2704
cstockton wants to merge 1 commit into
masterfrom
cs/sso-login-validation

Conversation

@cstockton

Copy link
Copy Markdown
Contributor

The SAML ACS handler refetches IdP metadata from metadata_url once it's stale and writes it straight into metadata_xml with no validation. If that fetch returns HTTP 200 with unexpected content the invalid metadata gets persisted over the last known good copy.

The admin update path already had these checks, I kept the error message identical to that flow.

The SAML ACS handler refetches IdP metadata from metadata_url once
it's stale and writes it straight into metadata_xml with no
validation. If that fetch returns HTTP 200 with unexpected content
the invalid metadata gets persisted over the last known good copy.

The admin update path already had these checks, I kept the error
message identical to that flow.
@cstockton
cstockton requested a review from a team as a code owner August 17, 2026 15:19
Comment thread internal/api/samlacs.go
rawMetadata, err := fetchSAMLMetadata(ctx, *ssoProvider.SAMLProvider.MetadataURL)
url := *ssoProvider.SAMLProvider.MetadataURL
rawMetadata, parsedMetadata, err := getSAMLMetadata(ctx, url)
if err == nil && parsedMetadata.EntityID != ssoProvider.SAMLProvider.EntityID {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Nice.

Comment thread internal/api/samlacs.go
url := *ssoProvider.SAMLProvider.MetadataURL
rawMetadata, parsedMetadata, err := getSAMLMetadata(ctx, url)
if err == nil && parsedMetadata.EntityID != ssoProvider.SAMLProvider.EntityID {
return apierrors.NewBadRequestError(apierrors.ErrorCodeSAMLEntityIDMismatch, "SAML Metadata can be updated only if the EntityID matches for the provider; expected '%s' but got '%s'", ssoProvider.SAMLProvider.EntityID, parsedMetadata.EntityID)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does this error get leaked to the user-agent?

Comment thread internal/api/samlacs.go

var userProvidedData provider.UserProvidedData

userProvidedData.Emails = append(userProvidedData.Emails, provider.Email{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: are we intentionally replacing the email instead of adding it?

Comment thread internal/api/ssoadmin.go
return data, nil
}

func getSAMLMetadata(ctx context.Context, url string) ([]byte, *saml.EntityDescriptor, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Nice refactoring!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants