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

Use CSPRNG if available. #18

Open
ericelliott opened this issue Jan 6, 2023 · 3 comments
Open

Use CSPRNG if available. #18

ericelliott opened this issue Jan 6, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@ericelliott
Copy link
Collaborator

ericelliott commented Jan 6, 2023

Note: Cuid2 already provides some cryptographically strong guarantees even using Math.random because:

  1. We don't trust the entropy from Math.random so we don't rely on it for cryptographic security. Instead, we mix it with several other independent sources of entropy. Those sources have been proven for more than a decade in apps with hundreds of millions of users via Cuid V1, and helped inspire UUID v6 - v8.
  2. We use a security audited implementation of the cryptographically secure SHA-3 to hash all that entropy so the output is opaque.

As far as we're aware, Cuid2 is safe to use now, and certainly safer than most other id options available.

Because we believe in security in layers, it's still a good idea to source our random bits with a CSPRNG. That is the purpose of this issue.

Idea:
Apparently all modern browsers + node support the cryptographically-secure crypto.randomUUID(), which may make a better source of pseudorandom data than Math.random().

@ericelliott ericelliott added the enhancement New feature or request label Jan 6, 2023
@xaevik
Copy link
Contributor

xaevik commented Jan 6, 2023

Wouldn't Crypto.getRandomValues() or SubtleCrypto.generateKey() be a better option?

@ericelliott
Copy link
Collaborator Author

No, because they are not universal (available in both browsers and Node), and their APIs are more prone to entropy problems, errors, and they need to be wrangled more to coerce their outputs into strings, adding complexity and potential for bugs.

@ericelliott ericelliott self-assigned this Jan 6, 2023
@ericelliott
Copy link
Collaborator Author

This isn't ready to merge yet:

  • Test with React Native
  • Make sure we're not using the fixed bits from UUID v4.
  • Is there a better solution? e.g. a cross-platform universal solution that is security audited and works like Math.random()?

@ericelliott ericelliott changed the title Seed with crypto.randomUUID() for CSRNG. Use CSPRNG if available. Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants