Skip to content

Commit

Permalink
Merge pull request #223 from twitter/handle-frozen-hashes
Browse files Browse the repository at this point in the history
Handle frozen hashes
  • Loading branch information
oreoshake committed Feb 29, 2016
2 parents 7958390 + 0c72911 commit 2cb0fba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/secure_headers/headers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def combine_policies(original, additions)
raise ContentSecurityPolicyConfigError.new("Attempted to override an opt-out CSP config.")
end

original = original.dup if original.frozen?

# in case we would be appending to an empty directive, fill it with the default-src value
additions.keys.each do |directive|
unless original[directive] || !source_list?(directive)
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/secure_headers/headers/content_security_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ module SecureHeaders
expect(csp.value).to eq("default-src https:; script-src https: anothercdn.com")
end

it "combines directives where the original value is nil and the hash is frozen" do
Configuration.default do |config|
config.csp = {
default_src: %w('self'),
report_only: false
}.freeze
end
combined_config = CSP.combine_policies(Configuration.get.csp, report_uri: %w(https://report-uri.io/asdf))
expect(combined_config[:report_uri]).to_not be_nil
end

it "overrides the report_only flag" do
Configuration.default do |config|
config.csp = {
Expand Down

0 comments on commit 2cb0fba

Please sign in to comment.