diff options
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/content_security_policy.rb | 12 | ||||
-rw-r--r-- | config/initializers/rack_attack_logging.rb | 4 | ||||
-rw-r--r-- | config/initializers/stoplight.rb | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 12b764a5a..2fe1a33fa 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -7,14 +7,24 @@ if Rails.env.production? data_hosts = [assets_host] if ENV['S3_ENABLED'] == 'true' - attachments_host = ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com" + attachments_host = "https://#{ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com"}" + attachments_host = "https://#{Addressable::URI.parse(attachments_host).host}" elsif ENV['SWIFT_ENABLED'] == 'true' attachments_host = ENV['SWIFT_OBJECT_URL'] + attachments_host = "https://#{Addressable::URI.parse(attachments_host).host}" else attachments_host = nil end + data_hosts << attachments_host unless attachments_host.nil? + if ENV['PAPERCLIP_ROOT_URL'] + url = Addressable::URI.parse(assets_host) + ENV['PAPERCLIP_ROOT_URL'] + data_hosts << "https://#{url.host}" + end + + data_hosts.uniq! + Rails.application.config.content_security_policy do |p| p.base_uri :none p.default_src :none diff --git a/config/initializers/rack_attack_logging.rb b/config/initializers/rack_attack_logging.rb index 2ddbfb99c..c30bd8a64 100644 --- a/config/initializers/rack_attack_logging.rb +++ b/config/initializers/rack_attack_logging.rb @@ -1,4 +1,6 @@ -ActiveSupport::Notifications.subscribe('rack.attack') do |_name, _start, _finish, _request_id, req| +ActiveSupport::Notifications.subscribe(/rack_attack/) do |_name, _start, _finish, _request_id, payload| + req = payload[:request] + next unless [:throttle, :blacklist].include? req.env['rack.attack.match_type'] Rails.logger.info("Rate limit hit (#{req.env['rack.attack.match_type']}): #{req.ip} #{req.request_method} #{req.fullpath}") end diff --git a/config/initializers/stoplight.rb b/config/initializers/stoplight.rb index 1bd4ee6e7..7384b2e9a 100644 --- a/config/initializers/stoplight.rb +++ b/config/initializers/stoplight.rb @@ -1,3 +1,4 @@ require 'stoplight' Stoplight::Light.default_data_store = Stoplight::DataStore::Redis.new(Redis.current) +Stoplight::Light.default_notifiers = [Stoplight::Notifier::Logger.new(Rails.logger)] |