Skip to content
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

fix: settings should persist return_to after required mfa login flow #3263

Merged
merged 19 commits into from Jun 29, 2023

Conversation

Benehiko
Copy link
Contributor

@Benehiko Benehiko commented May 2, 2023

Related issue(s)

fixes ory/network#222
fixes #2832

This PR fixes the incorrect behavior after completing the required login (MFA) required by the settings flow. Users would incorrectly be redirected to the /welcome page or default UI route after submitting a successful MFA credential instead of being redirected back to the original settings flow.

possible breaking change
Observed through the E2E tests, if the host from which the request to Kratos is proxied and the serve.public.base_url is set to point to the proxy URL, then Kratos will use the current host which is the Kratos URL. MFA required flows such as settings will attempt to redirect back to the Kratos Host instead of the proxy URL which is not automatically on the allow list for browser redirects - especially since our serve.public.base_url now points to the proxy URL instead of Kratos. This will cause the flow to fail and the user to be redirected to the /error page.

To avoid this, allow the proxy to forward the host through the X-Forwarded-Host header. Kratos will then correctly redirect back.

Before Merge:

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    security@ory.sh) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Merging #3263 (001c01a) into master (f884dfb) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 001c01a differs from pull request most recent head 0d7d373. Consider uploading reports for the commit 0d7d373 to get more accurate results

@@            Coverage Diff             @@
##           master    #3263      +/-   ##
==========================================
+ Coverage   77.82%   77.84%   +0.02%     
==========================================
  Files         325      325              
  Lines       21086    21100      +14     
==========================================
+ Hits        16410    16426      +16     
+ Misses       3446     3444       -2     
  Partials     1230     1230              
Impacted Files Coverage Δ
identity/handler.go 86.20% <ø> (ø)
selfservice/flow/login/handler.go 79.38% <ø> (ø)
selfservice/strategy/code/strategy_recovery.go 70.56% <ø> (ø)
session/manager.go 100.00% <ø> (ø)
selfservice/flow/login/hook.go 86.71% <100.00%> (+0.09%) ⬆️
selfservice/flow/settings/error.go 77.67% <100.00%> (-0.20%) ⬇️
selfservice/flow/settings/handler.go 69.56% <100.00%> (+1.17%) ⬆️
session/manager_http.go 78.97% <100.00%> (+0.89%) ⬆️

... and 1 file with indirect coverage changes

@Benehiko Benehiko force-pushed the fix-2fa-recovery-return-to branch 2 times, most recently from 31d0c8c to c42963f Compare May 3, 2023 16:39
@Benehiko Benehiko force-pushed the fix-2fa-recovery-return-to branch from f0d39f2 to 2c3a277 Compare May 9, 2023 20:24
@Benehiko Benehiko changed the title fix: get settings should persist return_to when redirecting to aal2 fix: settings should persist return_to after required mfa login flow May 9, 2023
@Benehiko Benehiko requested a review from jonas-jonas May 12, 2023 15:21
selfservice/flow/settings/handler.go Outdated Show resolved Hide resolved
session/manager_http.go Show resolved Hide resolved
test/e2e/profiles/kratos.base.yml Outdated Show resolved Hide resolved
test/e2e/proxy/proxy.js Outdated Show resolved Hide resolved
@Benehiko Benehiko force-pushed the fix-2fa-recovery-return-to branch 2 times, most recently from 7ffa1e1 to 0edd60a Compare June 21, 2023 06:09
@Benehiko Benehiko marked this pull request as ready for review June 21, 2023 09:48
@Benehiko Benehiko self-assigned this Jun 27, 2023
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just some comments

session/manager_http.go Show resolved Hide resolved
selfservice/strategy/code/strategy_recovery_test.go Outdated Show resolved Hide resolved
test/e2e/profiles/recovery-mfa/.kratos.yml Show resolved Hide resolved
selfservice/flow/login/handler.go Outdated Show resolved Hide resolved
selfservice/flow/settings/error.go Outdated Show resolved Hide resolved
selfservice/flow/settings/handler.go Show resolved Hide resolved
selfservice/flow/settings/handler.go Outdated Show resolved Hide resolved
selfservice/flow/settings/handler.go Outdated Show resolved Hide resolved
@Benehiko Benehiko requested a review from aeneasr June 28, 2023 05:59
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Benehiko Benehiko requested a review from zepatrik June 29, 2023 09:03
@Benehiko Benehiko merged commit 0ed1abd into master Jun 29, 2023
29 checks passed
@Benehiko Benehiko deleted the fix-2fa-recovery-return-to branch June 29, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants