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

Safari Crypto.getRandomValues error #9

Closed
nadenf opened this issue Oct 10, 2022 · 7 comments
Closed

Safari Crypto.getRandomValues error #9

nadenf opened this issue Oct 10, 2022 · 7 comments
Labels
invalid This doesn't seem right

Comments

@nadenf
Copy link

nadenf commented Oct 10, 2022

Getting the following error on Safari Mac (17614.1.25.9.10, 17614):

Can only call Crypto.getRandomValues on instances of Crypto

Does not appear in Chrome.

Looks like it was an issue with the ClosureScript implementation as well.

@armanbilge
Copy link
Member

I think this is similar to an error we encountered in scala-js/scala-js-dom#669 as well.

Chrome: TypeError: Illegal invocation
Firefox: TypeError: 'getRandomValues' called on an object that does not implement interface Crypto.

We should add Safari to CI.

@armanbilge
Copy link
Member

Actually @nadenf: can you confirm that your code does not throw an error in Chrome and/or Firefox? It's not obvious to me why Safari would behave differently here.

@nadenf
Copy link
Author

nadenf commented Oct 11, 2022

@armanbilge .. Had the same "Illegal invocation" error in Chrome as well but thought it was unrelated.

Ends up working if I switch to: scalajs-fake-insecure-java-securerandom.

@sjrd
Copy link
Member

sjrd commented Oct 11, 2022

Ends up working if I switch to: scalajs-fake-insecure-java-securerandom.

Please don't. This doesn't do what you want. It's insecure.

@sjrd
Copy link
Member

sjrd commented Oct 11, 2022

It seems some browsers don't like what amounts to the following:

const getRV = crypto.getRandomValues;
getRV(...);

They want a direct invocation like

crypto.getRandomValues(...);

@sjrd
Copy link
Member

sjrd commented Oct 13, 2022

Hum no but that doesn't make sense. We already call crypto.getRandomValues(buffer) exactly like that. Even Firefox complains if we do getRV(buffer).

So what is different on Safari? Also, how did you observe a failure in Chrome, even though we have Chrome set up in the CI?

There must be something else missing here. Are you using some kind of bundler that attempts to provide a polyfill of getRandomValues, perhaps? Or of the Node.js crypto module? Then perhaps it messes up and causes these issues?

@sjrd
Copy link
Member

sjrd commented Oct 13, 2022

I just did a test of testSuiteJS/testHtml on Safari, and the test suite passes in the browser. Therefore, I don't think this is an issue with this project at all. As I mentioned above, I suspect it's something to do with a bundling setup on your side.

@sjrd sjrd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2022
@sjrd sjrd added the invalid This doesn't seem right label Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants