fix(saml): respect redirectTo URL on ACS error redirects #2350
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.
Previously, SAML ACS errors always redirected to SiteURL, ignoring the redirectTo parameter stored in RelayState. This made it difficult to test SSO in development environments or with different redirect urls that handle sso logins.
Now
handleSamlAcsreturns the redirectTo URL along with errors, andSamlAcsuses it for error redirects when valid (falling back to SiteURL otherwise - so previous behavior is retained).What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Fixes #2349
When SAML SSO authentication fails, the error redirect always goes to the configured
SiteURL, completely ignoring theredirectToparameter that was passed tosignInWithSSO()and stored in RelayState.redirectToSiteURL(ignoresredirectTo)This happens because the error handler in
SamlAcs(lines 48-60) hardcodesa.config.SiteURLwithout checking if a validredirectTowas provided.What is the new behavior?
Error redirects now respect the
redirectToURL when it's valid (i.e., in the redirect allow list), falling back toSiteURLonly whenredirectTois empty or not whitelisted.redirectToredirectTo: redirects toredirectTowith error paramsredirectTo: redirects toSiteURLwith error paramsImplementation
Changed
handleSamlAcsto return(string, error)instead of justerror, where the string is theredirectToURL (if determined). TheSamlAcsfunction now uses this returned value for error redirects when valid.Additional context
This fix allows developers to properly test SSO flows in development/staging environments that use different domains than production, and enables applications to handle SSO errors in their intended context rather than being redirected away to a different domain.