-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
IdentityServer4: combo of response_mode=form_post and state protection not working #1664
Comments
Thanks for the information, I'll have a look at this! At a first glance, it seems to be an easy fix. |
It wasn't an easy fix after all... I think I know what causes the problem, but I'll have to try to find a way to solve it. Basically when |
Damn, if cookies are ignored, then |
Good news @wjkawecki! After some thorough digging, I managed to get this working locally! (I used Auth0, but I am confident that it will apply to IDS4.) The required changes were the following:
export default NextAuth({
...
cookies: {
csrfToken: {
name: 'next-auth.csrf-token',
options: {
httpOnly: true,
sameSite: 'none',
path: '/',
secure: true
}
},
pkceCodeVerifier: {
name: 'next-auth.pkce.code_verifier',
options: {
httpOnly: true,
sameSite: 'none',
path: '/',
secure: true
}
}
},
...
}) Refer to the documentation: https://next-auth.js.org/configuration/options#cookies So there is some interesting stuff going on, so let me try to explain. We override two cookies here, My research shows that state has been the way of protecting against CSRF attacks for a long time (ref: https://danielfett.de/2020/05/16/pkce-vs-nonce-equivalent-or-not/) But OAuth and OIDC have introduced two new ways, namely PKCE and Nonce. Currently, we only support PKCE, although once we switch to So even though (I THINK(!)) PKCE is more than enough protection in most cases, you can certainly use both The cookie overrides are needed because when you set For increased security, I also set With the above changes/settings, I have been able to successfully log in even when using
Hope this helps! (I certainly learned something.) |
Thank you @balazsorban44 for investigating this topic! I can confirm that custom cookie setup with Please let me know if I can help somehow with reviewing the |
@wjkawecki I merged #1669. I would be glad if your penetration test team had some feedback and gave their opinion on setting the CSRF Token and PKCE code verifier to This for example could be an issue:
If |
Thank you @balazsorban44, I've bumped the package version to latest. Pentest team is planning a retest round later this week - I'll get back to you once I have some feedback from their end. |
@balazsorban44 another round of penetration tests is through and the feedback is positive 🥳 High five! |
That is good to hear! I'm going to close this issue then, but keep in mind that this will probably start behaving strangely when |
I am using latest 3.14.0 release and have trouble setting up following provider:
When setting
response_mode
to'form_post'
(which enforces the IdP to send the data back via POST instead of GET https://identityserver4.readthedocs.io/en/latest/endpoints/authorize.html) I run into several issues. GET method works fine, but pen-test team insists to use POST.First is the fact, that state-handler accepts only state passed in query https://github.com/nextauthjs/next-auth/blob/main/src/server/lib/oauth/state-handler.js#L19
Whenever I change it to:
I am able to get a step further, to next issue. It appears that the existing and expected
state
calculation is somehow wrong:Does anyone have a similar setup and experience similar issues?
The text was updated successfully, but these errors were encountered: