Skip to content

Commit

Permalink
Merge pull request rails#36703 from y-yagi/script-src-xxx_and_style-s…
Browse files Browse the repository at this point in the history
…rc-xxx

Add support for script-src-attr / elem and style-src-attr / elem directives
  • Loading branch information
y-yagi authored Jul 18, 2019
2 parents 67705c8 + efae4c2 commit 027085a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def generate_content_security_policy_nonce
object_src: "object-src",
prefetch_src: "prefetch-src",
script_src: "script-src",
script_src_attr: "script-src-attr",
script_src_elem: "script-src-elem",
style_src: "style-src",
style_src_attr: "style-src-attr",
style_src_elem: "style-src-elem",
worker_src: "worker-src"
}.freeze

Expand Down
24 changes: 24 additions & 0 deletions actionpack/test/dispatch/content_security_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,36 @@ def test_fetch_directives
@policy.script_src false
assert_no_match %r{script-src}, @policy.build

@policy.script_src_attr :self
assert_match %r{script-src-attr 'self'}, @policy.build

@policy.script_src_attr false
assert_no_match %r{script-src-attr}, @policy.build

@policy.script_src_elem :self
assert_match %r{script-src-elem 'self'}, @policy.build

@policy.script_src_elem false
assert_no_match %r{script-src-elem}, @policy.build

@policy.style_src :self
assert_match %r{style-src 'self'}, @policy.build

@policy.style_src false
assert_no_match %r{style-src}, @policy.build

@policy.style_src_attr :self
assert_match %r{style-src-attr 'self'}, @policy.build

@policy.style_src_attr false
assert_no_match %r{style-src-attr}, @policy.build

@policy.style_src_elem :self
assert_match %r{style-src-elem 'self'}, @policy.build

@policy.style_src_elem false
assert_no_match %r{style-src-elem}, @policy.build

@policy.worker_src :self
assert_match %r{worker-src 'self'}, @policy.build

Expand Down

0 comments on commit 027085a

Please sign in to comment.