fix: consider OIDC registration flows errored with duplicate credential to be completed by strategy #3525
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.
Returning anything else here may cause Kratos to respond with two concatenated JSON objects: new login flow with actual error message as the first one and a very confusing '500, aborted registration hook execution' as the second one.
Related issue(s)
To reproduce this bug on current
master
:id_token
in the request body to avoid webview/redirections.This will trigger the code path designed to handle
identity.ErrDuplicateCredentials
and try to convert the registration to a login flow containing the expectedAn account with the same identifier (email, phone, username, ...) exists already.
message, then write this new login flow into HTTP response body. However, becauseregistration.ErrHookAbortFlow
is returned just a bit further, the outer request handler will write another object to the response body, this one containing very confusing "500, aborted registration hook execution" error.As far as I can tell, this is a malformed JSON.
Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further Comments
I discovered this when rebasing #3416 because I ran into it while investigating why e2e tests related to settings flows are suddenly failing. Even though applying this fix this didn't fix those tests for me, I realized that this issue wasn't caused by my code and can be also be reproduced on current
master
when I prepare the request in a way that avoids the OIDC redirection by other means, e.g. passing theid_token
from native Google SDK.Here's a picture with request made using Postman, showing an example of such malformed response:
By the way, is it actually allowed for Kratos to reply with a totally different kind of flow (in this case, login one) when calling POST / Update on another flow directly in the response body rather than always issuing a redirect, either via HTTP 303 or 422 with
{"error":{"id":"browser_location_change_required","code":422,"status":"Unprocessable Entity","message":"browser location change required"},"redirect_browser_to":"…/login?flow=…"}
? Because the reference React / SPA client used in e2e tests doesn't seem to handle this well and never displays theAn account with the same identifier (email, phone, username, ...) exists already.
message to the user, instead simply returning to main/welcome page.