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

Math.random() is not a cryptographically secure way to generate UUIDv4s #1101

Closed
gen0cide opened this issue Dec 29, 2020 · 2 comments · Fixed by #1585
Closed

Math.random() is not a cryptographically secure way to generate UUIDv4s #1101

gen0cide opened this issue Dec 29, 2020 · 2 comments · Fixed by #1585

Comments

@gen0cide
Copy link

gen0cide commented Dec 29, 2020

uuid4: () => {

The function uses an outdated method of generating UUIDv4s that does not follow current PRNG guidance for UUIDv4 generation.

The referenced comment above the function (https://stackoverflow.com/a/2117523) has an updated implemention:

function uuidv4() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  );
}

Given that Stripe is used for payment processing, it seems like sound cryptographic PRNG usage should be the default.

@brandur-stripe
Copy link
Contributor

brandur-stripe commented Jan 4, 2021

The new implementation would be an improvement, but just to be clear: idempotency keys are scoped entirely to single user accounts so the worst that could happen is that a user accidentally reuses one of their own idempotency keys, and even with a non-crypto random number generation, that's very unlikely to ever happen, especially since it would have to occur within a 24 hour window.

Exciting to see on the linked SO page that there's the UUID module is coming down the pipeline for inclusion in the core language.

@tjfontaine-stripe
Copy link

For tracking purposes, upstream is considering an implementation for inclusion as well nodejs/node#36729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants