Skip to content

[Prisma] Why is token field unique? #6655

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

Closed
jlalmes opened this issue Feb 9, 2023 · 1 comment
Closed

[Prisma] Why is token field unique? #6655

jlalmes opened this issue Feb 9, 2023 · 1 comment
Labels
prisma @auth/prisma-adapter question Ask how to do something or how something works

Comments

@jlalmes
Copy link

jlalmes commented Feb 9, 2023

Question 💬

The @next-auth/prisma-adapter docs show the required models and fields that must be added to your Prisma schema. The following is the VerificationToken model from that example schema:

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

Why is token given an @unique constraint when it is already included in the compound @@unique constraint with identifier?

One of the constraints should be removed, but which one?

How to reproduce ☕️

The setup docs 👉 https://next-auth.js.org/adapters/prisma#setup

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

@jlalmes jlalmes added the question Ask how to do something or how something works label Feb 9, 2023
@github-actions github-actions bot added the prisma @auth/prisma-adapter label Feb 9, 2023
@balazsorban44
Copy link
Member

balazsorban44 commented Feb 9, 2023

In theory, token doesn't have to be, but it is likely safer. When we query a VerificationToken from the DB, we use the combination of identifier and token.

This constraint was introduced a while ago as part of a security vulnerability patch. GHSA-pg53-56cg-4m8q

If you think it is fine to drop the unique constraint on token itself, you can do so.

But do not remove the @@unique([identifier, token]) constraint!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prisma @auth/prisma-adapter question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants