CSRF Token validation issue when "cookieValue" is not present #11391
Unanswered
juan-carlos-correa
asked this question in
Help
Replies: 1 comment
-
Btw, it's important to mention that this issue is happening only on headless mode tests. Not sure if this could affect the security of the authentication! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building an app using next-auth
5.0.0-beta.19
.When running Playwright login tests with
nodemailer
provider, the first tests are passing, but if I run the tests again, I'm having this error:I cloned the repo and debugged the error message because I have spent a weekend in this issue in my project ☕ and started guessing if this is actually a bug 🐛
I looked at : https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/lib/init.ts#L152C2-L176C4
The
createCSRFToken
is returningcsrfTokenVerified
value only if cookieValue exists. If doesn't exists, it won't return acsrfTokenVerified
value as we can see at: https://github.com/nextauthjs/next-auth/blob/a7a48a142f47e4c03d39df712a2bf810342cf202/packages/core/src/lib/actions/callback/oauth/csrf-token.ts#L26C1-L55C2 more specifically, this if:The
csrfTokenVerified
is used at: https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/lib/index.ts#L67And is used as a flag in the
case signin
:Where if
csrfTokenVerified
isfalsy
, it will throw the error mentioned at the beginning.Is this a bug? is this expected behavior?
This is the project I'm working on: https://github.com/product-makers-hub/open-micro-saas
There is the implementation and the tests.
The thing is that the issue is happening only in Playwright so far, I have not relased my app public yet and I'm wondering if it the auth will work with many users 😟
Please Heeeeeeeeeelp!
Beta Was this translation helpful? Give feedback.
All reactions