Skip to content

Commit 10dc425

Browse files
jrmhaigrafaelfranca
authored andcommitted
Add CSP mapping for 'wasm-unsafe-eval'
The `'wasm-unsafe-eval'` keyword for the Content Security Policy allows the loading and execution of WebAssembly modules without the need to allow unsafe JavaScript execution via `'unsafe-eval'`. A mapping is added so that the symbol `:wasm_unsafe_evel` can be used for this keyword in the policy configuration in `config/initializers/content_security_policy.rb`.
1 parent 630fc98 commit 10dc425

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

actionpack/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
* Add `:wasm_unsafe_eval` mapping for `content_security_policy`
2+
3+
```ruby
4+
# Before
5+
policy.script_src "'wasm-unsafe-eval'"
6+
7+
# After
8+
policy.script_src :wasm_unsafe_eval
9+
```
10+
11+
*Joe Haig*
112

213
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actionpack/CHANGELOG.md) for previous changes.

actionpack/lib/action_dispatch/http/content_security_policy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def generate_content_security_policy_nonce
126126
MAPPINGS = {
127127
self: "'self'",
128128
unsafe_eval: "'unsafe-eval'",
129+
wasm_unsafe_eval: "'wasm-unsafe-eval'",
129130
unsafe_hashes: "'unsafe-hashes'",
130131
unsafe_inline: "'unsafe-inline'",
131132
none: "'none'",

actionpack/test/dispatch/content_security_policy_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def test_mappings
4545
@policy.script_src :unsafe_eval
4646
assert_equal "script-src 'unsafe-eval'", @policy.build
4747

48+
@policy.script_src :wasm_unsafe_eval
49+
assert_equal "script-src 'wasm-unsafe-eval'", @policy.build
50+
4851
@policy.script_src :none
4952
assert_equal "script-src 'none'", @policy.build
5053

0 commit comments

Comments
 (0)