Skip to content

do not dedupe alternate schema source expresions #478

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

Merged
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
3 changes: 2 additions & 1 deletion lib/secure_headers/headers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ def dedup_source_list(sources)
wild_sources = sources.select { |source| source =~ STAR_REGEXP }

if wild_sources.any?
schemes = sources.map { |source| [source, URI(source).scheme] }.to_h
sources.reject do |source|
!wild_sources.include?(source) &&
wild_sources.any? { |pattern| File.fnmatch(pattern, source) }
wild_sources.any? { |pattern| schemes[pattern] == schemes[source] && File.fnmatch(pattern, source) }
end
else
sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ module SecureHeaders
expect(csp.value).to eq("default-src example.org")
end

it "does not deduplicate non-matching schema source expressions" do
csp = ContentSecurityPolicy.new(default_src: %w(*.example.org wss://example.example.org))
expect(csp.value).to eq("default-src *.example.org wss://example.example.org")
end

it "creates maximally strict sandbox policy when passed no sandbox token values" do
csp = ContentSecurityPolicy.new(default_src: %w(example.org), sandbox: [])
expect(csp.value).to eq("default-src example.org; sandbox")
Expand Down