fix: libsodium WASM is refused by the extension CSP on every popup load, silently falling back to asm.js #182
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by driving the real popup in a containerized Chrome (see #181). Not
reachable by the unit tests, because they run in node where no extension CSP
applies.
Observed
Every single load of
src/popup/index.htmlin a real browser emits an uncaughtpage error:
libsodium-wrappers-sumoships a WASM build and an asm.js fallback. Theextension CSP (
script-src 'self', correctly, with nowasm-unsafe-eval)refuses the WASM module, libsodium catches it and falls back to asm.js, and
everything continues to work - wallet creation, vault encryption and state
persistence were all verified working in the same session.
Why this matters anyway
vault.jsis the password-based encryption for the user's seed. Three concerns,in order of how much they should worry us:
under node, where WASM instantiates fine. So the crypto backend the tests
exercise is not the backend users actually get. Whatever confidence the test
suite provides for
vault.js, it provides it for the wrong build.If a future libsodium version drops or breaks the asm.js fallback, this
becomes a hard failure of wallet decryption, and the only warning we ever had
was a log line we had learned to ignore.
ever tuned against node timings, users are getting a slower unlock than
intended - or, worse, parameters were softened to compensate for a slowness
that only exists because of this.
Definition of done
being decided by a caught exception at runtime. Either:
wasm-unsafe-evalto the extension CSP and confirm the WASM backendactually loads (weighed against the fact that a wallet loosening its own
CSP deserves a hard look and may simply not be worth it), or
at all, and document why.
vault.jsunit tests must exercise the backend thatactually ships.
in this issue.
allowlist entry for this error removed.
Notes
Investigate whether the same applies to the Firefox MV2 build, whose CSP is
declared separately in
manifest/firefox.json.Recommendation: prefer shipping asm.js explicitly over loosening the CSP. A
wallet should not relax
script-srcfor a performance gain on an operation theuser performs a handful of times a session. But measure the unlock time before
deciding, rather than assuming - if the asm.js KDF is unacceptably slow, that is
a real argument and the tradeoff should be made on numbers.