Preserve continuation URL on OAuth2 error redirect

Use the ContinueURL from the state token so the user is redirected
back to where they initiated the flow instead of the root URL.
The redirect is safe because safeRedirect validates the host.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-04-06 21:11:08 +02:00
parent 47fc9df716
commit 4cc0e31214

View File

@@ -268,9 +268,15 @@ func handleConnectorOAuth2Error(
oauthErrDesc := query.Get("error_description")
provider := "unknown"
redirectURL := baseURL.String()
if stateToken := query.Get("state"); stateToken != "" {
if p, err := connector.ExtractProviderFromState(stateToken); err == nil {
provider = p
if payload, err := connector.DecodeOAuth2StatePayload(stateToken); err == nil {
if payload.Data.Provider != "" {
provider = payload.Data.Provider
}
if payload.Data.ContinueURL != "" {
redirectURL = payload.Data.ContinueURL
}
}
}
@@ -280,7 +286,7 @@ func handleConnectorOAuth2Error(
log.String("error_description", oauthErrDesc),
)
parsedURL, _ := url.Parse(baseURL.String())
parsedURL, _ := url.Parse(redirectURL)
q := parsedURL.Query()
q.Set("error", oauthErr)
if oauthErrDesc != "" {