Skip to content
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

Fix CSP copy boolean directives #31326

Merged
merged 5 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def initialize
end

def initialize_copy(other)
@directives = copy_directives(other.directives)
@directives = other.directives.deep_dup
end

DIRECTIVES.each do |name, directive|
Expand Down Expand Up @@ -174,10 +174,6 @@ def build(context = nil)
end

private
def copy_directives(directives)
directives.transform_values { |sources| sources.map(&:dup) }
end

def apply_mappings(sources)
sources.map do |source|
case source
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/content_security_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def test_build
assert_equal "script-src 'self';", @policy.build
end

def test_dup
@policy.img_src :self
@policy.block_all_mixed_content
@policy.upgrade_insecure_requests
@policy.sandbox
copied = @policy.dup
assert_equal copied.build, @policy.build
end

def test_mappings
@policy.script_src :data
assert_equal "script-src data:;", @policy.build
Expand Down