Skip to content

fix: correct error checking for recovery with mfa return_to #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/pkg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ export const isQuerySet = (x: any): x is string =>
const isErrorAuthenticatorAssuranceLevel = (
err: unknown,
): err is ErrorAuthenticatorAssuranceLevelNotSatisfied => {
const e = err as ErrorAuthenticatorAssuranceLevelNotSatisfied
return e.error?.id !== undefined && e.error?.id === "session_aal2_required"
console.log({ err })
return (
(err as ErrorAuthenticatorAssuranceLevelNotSatisfied).error?.id ==
"session_aal2_required"
)
}

// Redirects to the specified URL if the error is an AxiosError with a 404, 410,
Expand All @@ -62,15 +65,17 @@ export const redirectOnSoftError =
err.response.status === 410 ||
err.response.status === 403
) {
const error = err.response.data as { error: unknown }
if (error.error !== undefined) {
// in some cases Kratos will require us to redirect to a different page when the session_aal2_required
// for example, when recovery redirects us to settings
// but settings requires us to redirect to login?aal=aal2
if (isErrorAuthenticatorAssuranceLevel(error.error)) {
res.redirect(error.error.redirect_browser_to || redirectTo)
return
}
// in some cases Kratos will require us to redirect to a different page when the session_aal2_required
// for example, when recovery redirects us to settings
// but settings requires us to redirect to login?aal=aal2
const authenticatorAssuranceLevelError = err.response.data as unknown
if (
isErrorAuthenticatorAssuranceLevel(authenticatorAssuranceLevelError)
) {
res.redirect(
authenticatorAssuranceLevelError.redirect_browser_to || redirectTo,
)
return
}
res.redirect(`${redirectTo}`)
return
Expand Down