-
Notifications
You must be signed in to change notification settings - Fork 143
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
Chrome requires unsafe-eval to run webassembly code #196
Comments
We were able to get around this error by loosening our Content Security Policy to include:
Could you address the need for these headers in the .7 and up versions of |
I think this issue was closed, because the linked discussion indicates that libsodium.js errors, falls back to asm.js, and then continues to load and work properly. That is not the case in current versions of Chrome. The libsodium.js library will only load if the CSP includes |
Looks like Chrome currently requires https://github.com/WebAssembly/content-security-policy/blob/master/proposals/CSP.md |
Someone commented in Feb 2018 that the libsodium.js load could fallback from wasm.js to asm.js and load despite the error: emscripten-core/emscripten#5911 (comment) A request to get rid of the error message was placed from that thread. I think that state of that bug has changed. The error now stops libsodium.js from loading. Is it possible that handling this error better could allow this fallback from wasm.js to asm.js to take place and libsodium.js to load? |
It's supposed to be the case: https://github.com/jedisct1/libsodium/blob/8a1ac8e11fda8b77af0d9073f57475f9f66cb509/dist-build/emscripten.sh#L99-L123 If the module can't be compiled or doesn't work as expected (as originally seen on a specific iOS version), the fallback JS code is supposed to be run. Any exception should trigger the fallback code. But apparently not :( Can you help investigate why? That being said, I'm not sure that it's still worth keeping the Javascript version around. Besides IE, all the web browsers support it now. |
I sandboxed this to try and get the same result the above user mentioned of an error AND a load. I cannot get that result. I can even put this minimal code sample in an index.html file in VS Code, open it in Chrome, and open the inspector. With this 'unsafe-eval', it will console.log the hash. Without 'unsafe-eval', it will log the error and not load.
I can't think of anything that could be different between my code and that of the user who got the result of the error and the load. Anything other than the passing of a year+ and changes to Chrome and perhaps the libraries. I think getting the fallback to load will solve this issue... but why is it not loading... I am not sure. I haven't been able to come up with ways to investigate this part or try any hacks to find out. We don't have anyone particularly experienced with Web Assembly on our team. Right now, we can't ship, because we cannot load libsodium.js in Chrome without a broken, vulnerable CSP. So we are certainly open to being pointed in any direction we can take to figure this out and load libsodium.js without eval().
|
Can you wait for the I'm not sure that the |
In our actual application, we were using async / await sodium.ready. I can try to make a minimal code sample for that case to show that it's the same result. I tried this to double-check and strip out everything and get a minimal sandbox, and because the user who got libsodium.js to load specifically said the check was done using onload. Trying to pull away anything that could be the issue. From what I can tell, it's down to libsodium.js versions of .7 and up, Chrome, and the CSP |
Thanks for taking the time to look into this! We're really looking forward to getting past this block. |
Also, to be clear, the onload does work. If you add |
This code uses promises and should show the exact same pattern of error. I opened the index.html from VS Code in the Chrome browser and opened the inspector to see the logs and errors. If you remove the index.html
someCode.js
I got the |
I am wondering if fixing the way this error gets handled might be the solution. In this request, the assumption is that the fallback works. I have not been able to get the fallback to work: |
I think you're right. I've compiled it with the uglifier disabled, then you can see the error is caused by an uncaught error in abort. Adding the libsodium.js/wrapper/wrap-template.js Lines 8 to 37 in cdc31a7
So far so good, but if I re-enable the uglifier, it doesn't work anymore. My guess is that at some point an error is thrown by The root cause seems to be this: https://github.com/emscripten-core/emscripten/blob/59c14a2e5411ae8516a9dbe8222841d78ccc4998/src/postamble.js#L422. |
Thanks for looking into this! Any hope of us getting a fix in the near future? |
I've submitted a PR to emscripten, emscripten-core/emscripten#8558 that catches the unhandled promise rejection in Line 12 in ab256ef
. @jedisct1 I don't know if changing drop_console causes other issues?
|
|
I noticed some failing CI tests on this one emscripten-core/emscripten#8558 . Were those failures predicted with the changes that had to be made to get asm.js to load? |
Yeah I noticed it too. Not in my predictions, but too be honest I didn't know anything about emscripten before this weekend, so they're probably not very accurate ;). I'll try to run the tests locally to figure out if the changes caused them. |
Hi! It looks like there has been a lot of great progress on this fix. This is very exciting for us! Thanks for all your hard work! I couldn't quite follow the various PRs attached to this. I wanted to just check, is it thought that the fix is in place already? Or are some of the necessary changes still pending? Thanks again for all the hard work on this! We're really stoked to be able to ship some new file streaming features. |
No problem! I'm also developing a browser extension that relies on libsodium, so it was bothering me for a while as well. I think #198 still needs to be merged and then it should work. You'll might still see an error, but this now shouldn't prevent the asm from loading. emscripten-core/emscripten#8558 should make it easier to properly catch that error in the future. Whenever that one's finished and incorporated into the emscripten master branch, I'll submit a new PR to the libsodium repo to fix. For now you could use a workaround like:
This prevents the error from showing in the console. |
Thanks! Those workarounds don't seem to work in our sandbox. index.html
someCode.js
I was under the impression from the discussion online that Perhaps we would need to recompile libsodium for the other workaround. It seems like a lot of good progress is being made on this either way! So we can probably just sit tight. |
Ah sorry, I think |
Wow! Thanks! This does work in our sandbox. So we have a way forward regardless! |
@bas-d Your PR was merged yesterday! emscripten-core/emscripten#8558 I think you said there was one more PR to go to libsodium.js after that? Then perhaps I can confirm the fix, and we can close this! |
Yes to get rid of the error we would have to catch the promise rejection. This could be done by overriding https://emscripten.org/docs/api_reference/module.html#Module.instantiateWasm here: https://github.com/jedisct1/libsodium/blob/af6df5f4a591ea3216d80fb34694a3c292e9b51e/dist-build/emscripten.sh#L99. I think there's two options then:
@jedisct1, what approach would you prefer (if any)? I can make a PR for either. |
Rather than introduce hacks that will soon be useless and since your fix was merged into Emscripten, we can directly use the |
Hi! I just tested the |
We're still running into this issue with the latest versions of the When we add
@jmtucker7 did you get this working on your side? |
Looks like unsafe-eval is still needed https://dev.to/aaronpowell/using-webassembly-with-csp-headers-597o |
Is there a way to configure the library to fall back to asm.js and stop throwing a CSP error about wasm? |
I just switched to libsodium and had nearly a heart attack when that error was reported by sentry. I thought i broke everything but it seems still to work, only an ugly error. But still, any "workaround" that would silence the error without the need for |
Hello.
We have a Docker container that uses Nginx to serve static files of a React app that uses libsodium-wrappers. In Chrome, versions up to .5 work without error, and versions over .7 throw an error as soon as the page loads on libsodium.js. We have sandboxed this issue, and versions under .7 work properly, as well as all versions when we build and serve them without using Docker. The error does not occur in Firefox.
Any help resolving this issue would be greatly appreciated!
The text was updated successfully, but these errors were encountered: