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 insecure default id for invites #1789

Merged
merged 2 commits into from
Jan 3, 2025
Merged

Fix insecure default id for invites #1789

merged 2 commits into from
Jan 3, 2025

Conversation

ekzyis
Copy link
Member

@ekzyis ekzyis commented Jan 3, 2025

Description

cuid has been deprecated due to security, see README.

cuid2 is now recommended but when I tried to use cuid(2) as the default in our Prisma schema as mentioned in the Prisma docs, it didn't work.

Error: Prisma schema validation - (validate wasm)
Error code: P1012
error: Error parsing attribute "@default": The `cuid` function does not take any argument. Consider changing this default to `cuid()`.
  -->  prisma/schema.prisma:470
   |
469 | model Invite {
470 |   id          String   @id @default(cuid(2))
   |

Validation Error Count: 1
[Context: validate]

Prisma CLI Version : 5.20.0

Since Prisma is pretty weird anyway and I have more trust in pgcrypto, I decided to use gen_random_bytes from it.

I used hex encoding because it's url-safe, I only wanted to have alphanumeric characters and Postgres only supports base64 or hex as encodings.

TODO:

  • use 16 bytes

Additional Context

Checklist

Are your changes backwards compatible? Please answer below:

it doesn't fix existing invite links

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:

7. Created invite link with default id and custom id.

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

n/a

Did you introduce any new environment variables? If so, call them out explicitly here:

no

@ekzyis ekzyis added the bug label Jan 3, 2025
@ekzyis ekzyis marked this pull request as draft January 3, 2025 15:20
@ekzyis ekzyis marked this pull request as ready for review January 3, 2025 15:27
@huumn huumn merged commit 47debbc into master Jan 3, 2025
6 checks passed
@huumn huumn deleted the fix-invite-cuid-insecure branch January 3, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants