fix(wasm): load without script-src 'unsafe-eval' - #717
Merged
Conversation
embind generates its invoker functions at run time with `new Function`, which CSP treats as eval, so `Odr.load()` threw an `EvalError` under any policy that did not grant `'unsafe-eval'` — the one thing a page whose selling point is that documents are processed locally would rather not grant. The glue contains no literal `eval(`, which makes it easy to misdiagnose. `-sDYNAMIC_EXECUTION=0` picks embind's closure-based path instead. What it costs is `emscripten_run_script`, `dlopen`, and `ccall`/`cwrap` for anything not exported in advance — none of which the bindings use. `script-src 'self' 'wasm-unsafe-eval'` is now enough. Closes #709 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDs5aK3ZGSZsEvqUUwBBXU
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015d5RcmsA777vwXiuafjx6k
andiwand
force-pushed
the
fix/wasm-no-dynamic-execution
branch
from
August 20, 2026 12:25
a3451ff to
99b6eb1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Closes #709.
embind generates its invoker functions at run time with
new Function, which CSP treats as eval — soOdr.load()threwunder the policy a page whose selling point is that documents are processed locally would actually want to ship. The glue contains no literal
eval(, which is what makes it easy to misdiagnose.-sDYNAMIC_EXECUTION=0picks embind's closure-based path instead (#if DYNAMIC_EXECUTION == 0inembind.js, present in the pinned emsdk 3.1.73). What it costs isemscripten_run_script,dlopen, andccall/cwrapfor anything not exported in advance — none of which the bindings use.script-src 'self' 'wasm-unsafe-eval'is now enough.Verified
Built locally with the
emscripten-wasmprofile, emsdk 3.1.73:new Function/eval(inodr-core.mjsEvalErroratinitRuntimeodr-core.wasm, brotliThe "blocked" run is a child process with
globalThis.Functionproxied to throw on construct and apply, standing in for a policy without'unsafe-eval'; it rendersmixed-layout.odtend to end afterwards. That is the first of the two tests inwasm/tests/csp.test.mjs; the second asserts statically that the shipped glue builds no code at run time, so dropping the flag fails the suite rather than only failing in a browser.Note: this documents only the module's own
script-srcline, under Hosting. What the rendered output needs — #710 — is a separate section in a separate PR; the two do not overlap.