-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
CSRF vulnerability in the NextAuth Email provider #2460
Comments
Thank you for your concern and reaching out. I think this has been touched on in the past, and Iain actually gave a detailed explanation here, why this is not an actual issue in our case: Also #1913 (comment) might be similar in spirit. If you have further concerns, maybe you could create a reproduction? |
Thank you for sharing the additional context on this topic. If this is by design, may I suggest this be clearly documented in the Email provider documentation? I believe it will be beneficial for NextAuth users to be aware of how email links work in NextAuth. I'm sure some NextAuth users may see this as a security flaw the way I do (and in my opinion it's clearly a CSRF vulnerability). I also looked into the documentation of the major commercial authentication providers, and it seems like none of them allow magic link authentication to take place outside of the original browser/device context.
|
The lack of anti-CSRF measures in the magic link authentication flow is equivalent to the lack of a CSRF prevention mechanism in the username/password authentication form. It exposes a website to the same attack vectors. Here are some articles highlighting the importance of anti-CSRF measures in the authentication process. https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#login-csrf |
I'm aware of the importance of CSRF, but the original implementation of the Email provider wasn't done by me and I trusted the creator of their research. @iaincollins did study OWASP and I'm pretty sure that he intended to follow their guidelines. Thank you for bringing up other examples. Iain is unfortunately less active nowadays, but I'll try to discuss this with the rest of the team to decide what the next step should be. |
Iain reached out and he told me he will share his opinion on this once he finds the time, but in short, we do not concider it as an actual vulnerability, and it does not fall under CSRF either. |
I'm honestly failing to see how it's not a CSRF as it does look like a textbook CSRF. I'll await Iain's explanation, but in the meantime, I thought I would provide a code sandbox demonstrating the issue. https://codesandbox.io/s/hardcore-kowalevski-nv6x0 Steps to reproduce:
|
I will quote what he wrote as-is until he gets around this issue to hopefully shed some more light on his thoughts if you won't be satisfied with the following:
@iaincollins is right. I just verified this with OpenCollective. I sent an e-mail to myself on my phone from my main browser, then switched on VPN, disconnected Wi-Fi (to use cellular data), opened a totally different browser in incognito mode, pasted the link I got in my e-mail, and it successfully logged me in. Read more about this here: https://docs.opencollective.com/help/product/log-in-system#about-security TLDR; they recite a company specialized in penetration testing:
I guess you are also not wrong that this flow could be made more secure only by allowing the same browser context to execute the login flow, but this would be at the cost of convenience. And this has already been discussed in #1051 as a possible optional enhancement. We could definitely mention this in the documentation though, so if you feel this is important, please open a PR! |
I will leave this up to dictionary police how to properly call this flaw, but CSRF is not limited to HTTP POST calls. https://owasp.org/www-community/attacks/csrf#get-scenario describes pretty much identical scenario with HTTP GET call.
Hmmm... I would trust Magic, Okta and Auth0 more on this...
Agree. Some users may get upset when they initiate login in Chrome but magic link opens in Safari and transaction fails. Security can't be convenient in 100% cases. |
I, unfortunately, don't have the deep knowledge to try convincing you further, will leave it to @iaincollins. But I do think OpenCollective is a big enough actor that if that this flow works for them, it will work for many (Yes, probably not everybody). As mentioned they have been audited by professionals who did give suggestions for improvement but did not find the login process flawed. |
Is there a work around to enforce sign in from the same browser? |
Description 🐜
Hi,
I want to report CSRF vulnerability in the NextAuth Email provider.
The issue here is that NextAuth does not verify that the "magic link" authentication request is coming from the same browser that requested it in the first place (csrf-token cookie is not getting validated).
Scenario:
To eliminate this flaw, NextAuth could:
a) derive email verification token from csrf token
b) perform csrf cookie validation during authentication call
This issue was reported to [email protected] on 6/23/2021 as per security guidelines, but there was no response.
Is this a bug in your own project?
No
How to reproduce ☕️
See scenario above
Screenshots / Logs 📽
No response
Environment 🖥
N/A
Contributing 🙌🏽
Yes, I am willing to help solve this bug in a PR
The text was updated successfully, but these errors were encountered: