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
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Metrics/ParameterLists:
Max: 7

Metrics/ClassLength:
Max: 300
Max: 350

Metrics/ModuleLength:
Max: 300
Max: 350

2 changes: 1 addition & 1 deletion lib/rackr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Rackr is a simple router for Rack.
class Rackr
VERSION = '0.0.70'
VERSION = '0.0.71'

class NotFound < StandardError; end

Expand Down
1 change: 1 addition & 0 deletions lib/rackr/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def content_security_policy
@content_security_policy ||=
DEFAULT_CSP_HEADERS
.merge(config&.dig(:csp_headers) || {})
.compact
.map { |k, v| "#{k.to_s.tr('_', '-')} #{v}" }
.join('; ')
end
Expand Down
26 changes: 26 additions & 0 deletions lib/spec/rackr/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,32 @@ class SomeClass2
end
end

context 'when removing csp_headers' do
let(:config) do
{
csp_headers: {
style_src: nil,
}
}
end

let(:expected_csp) do
default = {
base_uri: "'self'", child_src: "'self'", connect_src: "'self'",
default_src: "'none'", font_src: "'self'", form_action: "'self'",
frame_ancestors: "'self'", frame_src: "'self'",
img_src: "'self' https: data:", media_src: "'self'",
object_src: "'none'", script_src: "'self'",
}
default.map { |k, v| "#{k.to_s.tr('_', '-')} #{v}" }.join('; ')
end

it 'merges and overrides the default csp' do
result = subject.render(html: 'test')
expect(result[1]['content-security-policy']).to eq(expected_csp)
end
end

context 'with user-defined csp_headers' do
let(:config) do
{
Expand Down
Binary file removed rackr-0.0.70.gem
Binary file not shown.
Binary file added rackr-0.0.71.gem
Binary file not shown.