Fix: SAML login fails for inline metadata containing a UTF-8 BOM (#3994)#3995
Closed
cweibel wants to merge 1 commit into
Closed
Fix: SAML login fails for inline metadata containing a UTF-8 BOM (#3994)#3995cweibel wants to merge 1 commit into
cweibel wants to merge 1 commit into
Conversation
…ed correctly Inline SAML IDP metadata that begins with a UTF-8 BOM (U+FEFF) -- as served by Microsoft Entra/ADFS federationmetadata.xml and frequently pasted verbatim into idpMetadata -- was misclassified by SamlIdentityProviderDefinition.getType(). String.trim() only strips characters <= U+0020, so the BOM survived and the startsWith checks failed, returning UNKNOWN instead of DATA. Since cloudfoundry#3971 routed the live login path through resolveMetadataXml() and thence getType(), that latent gap surfaced as a login failure: RelyingPartyRegistrationBuilder sent the non-DATA metadata to RelyingPartyRegistrations.fromMetadataLocation(), which treated the multi-KB XML blob as a resource location and threw FileNotFoundException -> Saml2Exception (HTTP 500 on /saml2/authenticate/{origin}). Strip a leading BOM in getType() (fixes all call sites) and also normalize the bytes returned by SamlIdentityProviderConfigurator.resolveMetadataXml() as defense-in-depth for URL endpoints that serve BOM-prefixed metadata. Add regression tests in SamlIdentityProviderDefinitionTests and ConfiguratorRelyingPartyRegistrationRepositoryTest. Fixes cloudfoundry#3994
Contributor
Author
|
Closing in favor of #3993, which addresses the same root cause (BOM defeating DATA/URL classification in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After
79.3.0→79.4.0, SAML login fails for IdPs whose inline metadata (idpMetadata: <EntityDescriptor…>) begins with a UTF-8 BOM (U+FEFF). This is common for Microsoft Entra / Azure AD / ADFSfederationmetadata.xml, which is served UTF-8-with-BOM and pasted verbatim into config.GET /saml2/authenticate/{origin}returns HTTP 500:Fixes #3994.
Root cause
SamlIdentityProviderDefinition.getType(String)classifies metadata as inline XML (DATA) vsURLby prefix-matching afterString.trim().String.trim()only removes characters<= U+0020, so a leading BOM survives and thestartsWith("<?xml")/startsWith("<EntityDescriptor")checks fail → the value is classifiedUNKNOWN.RelyingPartyRegistrationBuilderthen sends anything notDATAtoRelyingPartyRegistrations.fromMetadataLocation(...), which treats the XML blob as a resource location and throwsFileNotFoundException.This was a latent gap in
getType(); it surfaced on the login path when #3971 routed live login throughSamlIdentityProviderConfigurator.resolveMetadataXml()→getType(). (Distinct from the other #3971 follow-up, #3974.)Fix
U+FEFFinSamlIdentityProviderDefinition.getType()before classification — minimal change, fixes all call sites (login, admin/validate, metadata delegate).SamlIdentityProviderConfigurator.resolveMetadataXml()(covers URL endpoints that serve BOM-prefixed metadata).Tests
SamlIdentityProviderDefinitionTests:getType()classifies BOM-prefixed inline XML asDATAand BOM-prefixed URL asURL.ConfiguratorRelyingPartyRegistrationRepositoryTest: BOM-prefixed inline metadata resolves to a validRelyingPartyRegistration.Verification
Rollback
Revert this commit; no schema, config, or API changes.
Security impact
Affects SAML IdP metadata parsing/classification only. No change to signature validation, trust, or authorization; BOM stripping is limited to a single leading
U+FEFFbefore XML parsing (which OpenSAML already tolerates).