diff --git a/.rubocop.yml b/.rubocop.yml index 7ec66ff..2942fec 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -44,8 +44,8 @@ Metrics/ParameterLists: Max: 7 Metrics/ClassLength: - Max: 300 + Max: 350 Metrics/ModuleLength: - Max: 300 + Max: 350 diff --git a/lib/rackr.rb b/lib/rackr.rb index f08756a..0715778 100644 --- a/lib/rackr.rb +++ b/lib/rackr.rb @@ -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 diff --git a/lib/rackr/action.rb b/lib/rackr/action.rb index 69e893c..d6db77b 100644 --- a/lib/rackr/action.rb +++ b/lib/rackr/action.rb @@ -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 diff --git a/lib/spec/rackr/action_spec.rb b/lib/spec/rackr/action_spec.rb index f69e576..0034c51 100644 --- a/lib/spec/rackr/action_spec.rb +++ b/lib/spec/rackr/action_spec.rb @@ -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 { diff --git a/rackr-0.0.70.gem b/rackr-0.0.70.gem deleted file mode 100644 index 74a14da..0000000 Binary files a/rackr-0.0.70.gem and /dev/null differ diff --git a/rackr-0.0.71.gem b/rackr-0.0.71.gem new file mode 100644 index 0000000..b1632f5 Binary files /dev/null and b/rackr-0.0.71.gem differ