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

getRandomValues couldn't be found from a WebWorker in Edge18 #392

Closed
evertbouw opened this issue Mar 2, 2020 · 6 comments
Closed

getRandomValues couldn't be found from a WebWorker in Edge18 #392

evertbouw opened this issue Mar 2, 2020 · 6 comments

Comments

@evertbouw
Copy link

Describe the bug

I've used uuid v4 in a webworker but now I'm seeing error logs from Edge18.

SCRIPT0: SCRIPT0: uuid: This browser does not seem to support crypto.getRandomValues(). If you need to support this browser, please provide a custom random number generator through options.rng.
27788d0bfdaa0d0b9446.worker.js (2,1)

Runtime

  • OS: Windows 10
  • Runtime: Edge
  • Runtime Version: EdgeHTML 18.19041
@ctavan
Copy link
Member

ctavan commented Mar 2, 2020

@evertbouw can you please provide steps to reproduce as requested by the issue template? Thanks!

@evertbouw
Copy link
Author

I thought that would look a little bit silly as it's just repeating call v4 in a webworker in Edge, but I'll try to get a minimal repro online

ctavan added a commit that referenced this issue Mar 2, 2020
Edge does not appear to make a global `crypto` variable available in
WebWorkers however the WebCrypto seems to be exposed on the `self`
variable, see sodium-friends/sodium-javascript#8

Since window.self also points to the window object in browsers checking
self should work both, in the browser as well as in WebWorkers.

Fixes #392
@ctavan
Copy link
Member

ctavan commented Mar 2, 2020

Thank you for the reproduction code, that was really helpful!

Unfortunately, according to https://caniuse.com/#feat=cryptography, the WebCrypto API is not supported in WebWorkers in Edge<=18.

There was an issue regarding that problem on the old Edge Issuetracker which is no longer available: https://web.archive.org/web/20171210184325/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7607496/

Unfortunately this means that if you want to continue to support pre-Chromium Edge Versions you will either have to continue to use [email protected] or you have to supply your own random number generator to the v4() method through options.rng.

You could take a look at the old version of this library where we were shipping an insecure fallback random number generator for environments that do not support proper cryptographically secure random number generators: https://github.com/uuidjs/uuid/blob/v3.4.0/lib/rng-browser.js#L24-L33

However, please be aware that using a flawed random number generator might lead to unexpected consequences, see https://github.com/tc39/proposal-uuid#how-unique-are-v4-uuids for examples.

@broofa
Copy link
Member

broofa commented Mar 2, 2020

@ctavan 'worth noting that this a perfect example of why Math.getRandomValues() is needed.

@evertbouw
Copy link
Author

Thanks!

I wasn't sure if this was intended because I couldn't really find anything on Google. In my worker I guess I used uuid out of habit but an auto increment id should suffice so I'm doing that now.

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

No branches or pull requests

3 participants