keystonejs / keystone

The most powerful headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
8.98k stars 1.13k forks source link

Deprecation of cuid, upgrade to cuid2 #8282

Open dcousens opened 1 year ago

dcousens commented 1 year ago

https://github.com/paralleldrive/cuid has been deprecated by @ericelliott in favour of cuid2. The reasoning for the deprecation is

Cuid and other k-sortable and non-cryptographic ids (Ulid, ObjectId, KSUID, all UUIDs) are all insecure. Use @paralleldrive/cuid2 instead.

cuid2 is effectively a random 24 character base36 string. Prisma has an open issue for cuid2 https://github.com/prisma/prisma/issues/17102, which will be an easy transition for us, but is thereby blocking for now.

Related

DrJume commented 1 year ago

The length of cuid2 can be configured. It is base36 encoded with the first character always being a letter.

dcousens commented 1 year ago

@DrJume are you saying that we should change the default length?

~Isn't it base26?~ No, it uses .toString(36) for the rest of the string, amended the OP

DrJume commented 1 year ago

Nono, just wanted to inform you that cuid2 is not always 24 characters long. https://github.com/paralleldrive/cuid2#parameterized-length

dcousens commented 1 year ago

@tomdo1234 recently reported this as a security vulnerability, and I have opened an advisory in https://github.com/keystonejs/keystone/security/advisories/GHSA-5fp6-4xw3-xqq3 - with the following justification:

You might actually want the features of a monotonically increasing (auto-increment, k-sortable), and timestamp-based id as part of your application, and keystone should support that - but you might not want them by default. This is why this security advisory has been accepted by me (@dcousens) we currently use cuid identifiers by default, and that should change.

dcousens commented 12 months ago

As of https://github.com/keystonejs/keystone/pull/8648 (to be released soon), you can now use

  db: { idField: { kind: 'cuid2' } }

On your lists to use cuid2 as your identifiers, and you can probably upgrade your lists in a non-breaking way if you are using your identifiers relatively opaquely.

In our next major update, we will change the default to cuid2 to resolve https://github.com/keystonejs/keystone/security/advisories/GHSA-5fp6-4xw3-xqq3.