Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: ruby

rvm:
- ruby-head
- 2.4.2
- 2.3.5
- 2.2.8
- 2.6
- 2.5
- 2.4
- jruby-head

env:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group :test do
gem "pry-nav"
gem "rack"
gem "rspec"
gem "rubocop"
gem "rubocop", "< 0.68"
gem "rubocop-github"
gem "term-ansicolor"
gem "tins"
Expand Down
10 changes: 8 additions & 2 deletions lib/secure_headers/headers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ def build_source_list_directive(directive)
end

if source_list != OPT_OUT && source_list && source_list.any?
normalized_source_list = minify_source_list(directive, source_list)
[symbol_to_hyphen_case(directive), normalized_source_list].join(" ")
minified_source_list = minify_source_list(directive, source_list).join(" ")

if minified_source_list.include?(";")
Kernel.warn("#{directive} contains a ; in '#{minified_source_list}' which will raise an error in future versions. It has been replaced with a blank space.")
end

escaped_source_list = minified_source_list.gsub(";", " ")
[symbol_to_hyphen_case(directive), escaped_source_list].join(" ").strip
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ module SecureHeaders
expect(ContentSecurityPolicy.new.value).to eq("default-src https:; form-action 'self'; img-src https: data: 'self'; object-src 'none'; script-src https:; style-src 'self' 'unsafe-inline' https:")
end

it "deprecates and escapes semicolons in directive source lists" do
expect(Kernel).to receive(:warn).with("frame_ancestors contains a ; in 'google.com;script-src *;.;' which will raise an error in future versions. It has been replaced with a blank space.")
expect(ContentSecurityPolicy.new(frame_ancestors: %w(https://google.com;script-src https://*;.;)).value).to eq("frame-ancestors google.com script-src * .")
end

it "discards 'none' values if any other source expressions are present" do
csp = ContentSecurityPolicy.new(default_opts.merge(child_src: %w('self' 'none')))
expect(csp.value).not_to include("'none'")
Expand Down