【问题标题】:How can I provide HSTS support in Rails 4如何在 Rails 4 中提供 HSTS 支持
【发布时间】:2019-04-26 11:20:15
【问题描述】:

在 Rails 5 中,我们可以执行以下操作: config.ssl_options = { hsts: { expires: 10.days } }

我发现一篇旧文章说我可以强制执行它

  before_filter :strict_transport_security
  def strict_transport_security
    if request.ssl?
      response.headers['Strict-Transport-Security'] = "max-age=31536000; includeSubDomains"
    end
  end

在这个文件中有一个 HSTS 方法,这是否意味着它在 Rails 4.2 中默认开启? https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/middleware/ssl.rb

【问题讨论】:

  • 我刚刚看到# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true 这是否在 ssl 选项中设置了 hsts?

标签: ruby-on-rails ruby-on-rails-4 hsts


【解决方案1】:

Rails 5 添加了更多选项,您可以在 ssl_options 中指定,但 Rails 4 已经有了基本选项,包括 hsts: { expires: 10.days, subdomains: false },正如您在代码中看到的那样。

config.force_ssl = true
config.ssl_options = { hsts: { expires: 10.days, subdomains: false } }

【讨论】:

  • 所以我可以在 config.ssl_options 中设置 hsts: { expires: 10.days, subdomains: false }?
  • @CJW 是的,类似于 rails 5
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
  • 2018-06-11
相关资源
最近更新 更多