Skip to content

Commit c69842e

Browse files
committed
CSP exploration
1 parent a1fbf1a commit c69842e

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gem 'mitlibraries-theme', git: 'https://github.com/mitlibraries/mitlibraries-the
1414
gem 'puma'
1515
gem 'rack-attack'
1616
gem 'rails', '~> 7.1.0'
17+
gem 'redis'
1718
gem 'sentry-rails'
1819
gem 'sentry-ruby'
1920
gem 'sprockets-rails'

Gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ GEM
285285
rake (13.2.1)
286286
rdoc (6.12.0)
287287
psych (>= 4.0.0)
288+
redis (5.4.0)
289+
redis-client (>= 0.22.0)
290+
redis-client (0.24.0)
291+
connection_pool
288292
regexp_parser (2.10.0)
289293
reline (0.6.0)
290294
io-console (~> 0.5)
@@ -419,6 +423,7 @@ DEPENDENCIES
419423
puma
420424
rack-attack
421425
rails (~> 7.1.0)
426+
redis
422427
rubocop
423428
rubocop-rails
424429
selenium-webdriver

config/environments/production.rb

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
# Use a different cache store in production.
6868
# config.cache_store = :mem_cache_store
69+
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
6970

7071
# Use a real queuing backend for Active Job (and separate queues per environment).
7172
# config.active_job.queue_adapter = :resque

config/initializers/content_security_policy.rb

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
# See the Securing Rails Applications Guide for more information:
55
# https://guides.rubyonrails.org/security.html#content-security-policy-header
66

7-
# Rails.application.configure do
8-
# config.content_security_policy do |policy|
9-
# policy.default_src :self, :https
10-
# policy.font_src :self, :https, :data
11-
# policy.img_src :self, :https, :data
12-
# policy.object_src :none
13-
# policy.script_src :self, :https
14-
# policy.style_src :self, :https
15-
# # Specify URI for violation reports
16-
# # policy.report_uri "/csp-violation-report-endpoint"
17-
# end
18-
#
19-
# # Generate session nonces for permitted importmap, inline scripts, and inline styles.
20-
# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21-
# config.content_security_policy_nonce_directives = %w(script-src style-src)
22-
#
23-
# # Report violations without enforcing the policy.
24-
# # config.content_security_policy_report_only = true
25-
# end
7+
Rails.application.configure do
8+
config.content_security_policy do |policy|
9+
policy.default_src :self, :https
10+
policy.font_src :self, :https, :data
11+
policy.img_src :self, :https, :data
12+
policy.object_src :none
13+
policy.script_src :self, :https, :unsafe_inline
14+
policy.style_src :self, :https, :unsafe_inline
15+
# Specify URI for violation reports
16+
# policy.report_uri "/csp-violation-report-endpoint"
17+
end
18+
#
19+
# Generate session nonces for permitted importmap, inline scripts, and inline styles.
20+
# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21+
# config.content_security_policy_nonce_directives = %w(script-src style-src)
22+
#
23+
# Report violations without enforcing the policy.
24+
config.content_security_policy_report_only = true
25+
end

0 commit comments

Comments
 (0)