Fix #3522: Enable HSTS.

This commit is contained in:
evazion
2018-01-28 19:57:45 -06:00
parent 2fd91bfa20
commit 09462aefeb
2 changed files with 31 additions and 0 deletions

View File

@@ -26,6 +26,17 @@ module Danbooru
config.action_mailer.perform_deliveries = true
config.log_tags = [lambda {|req| "PID:#{Process.pid}"}]
config.action_controller.action_on_unpermitted_parameters = :raise
config.force_ssl = true
if Rails.env.production? && Danbooru.config.ssl_options.present?
config.ssl_options = Danbooru.config.ssl_options
else
config.ssl_options = {
hsts: false,
secure_cookies: false,
redirect: { exclude: ->(request) { true } }
}
end
if File.exists?("#{config.root}/REVISION")
config.x.git_hash = File.read("#{config.root}/REVISION").strip

View File

@@ -198,6 +198,26 @@ module Danbooru
1.week.ago
end
# Permanently redirect all HTTP requests to HTTPS.
#
# https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
# http://api.rubyonrails.org/classes/ActionDispatch/SSL.html
def ssl_options
{
redirect: { exclude: ->(request) { request.subdomain == "insecure" } },
hsts: {
expires: 1.year,
preload: true,
subdomains: false,
},
}
end
# Disable the forced use of HTTPS.
# def ssl_options
# false
# end
# The name of the server the app is hosted on.
def server_host
Socket.gethostname