ruby-on-rails - 如何保护 Rails 应用程序免受 Firesheep 攻击?

标签 ruby-on-rails security

我还没有找到一个简单的指南来保护 Ruby on Rails 应用程序免受 Firesheep 的影响。 .

如果您不知道,如果您的应用程序不强制使用 SSL 并在 cookie 中设置安全标志,Firesheep 会提取 session cookie。我不得不做一些搜索才能找到这两件事,所以我想我会在这里发布我找到的东西,看看是否还有其他我遗漏的东西。

第一步强制 SSL

我发现有两种方法可以做到这一点。一种是使用ssl_requirement插件,但这很痛苦,因为您必须专门指定 ssl_required :action1, :action2在每个 Controller 中。

最好的方法似乎是使用机架中间件,通过这篇文章:Force SSL using ssl_requirement in Rails 2 app .奇迹般有效。

第二步使 cookie 安全

为此,我关注了 these directions ,它告诉您将以下内容放入您的 config/environment/production.rb文件:

config.action_controller.session = {
    :key     => 'name_of_session_goes_here',
    :secret          => 'you need to fill in a fairly long secret here and obviously do not copy paste this one',
    :expire_after    => 14 * 24 * 3600, #I keep folks logged in for two weeks
    :secure => true #The session will now not be sent or received on HTTP requests.
  }

这在我的 Rails 2.x 应用程序中非常简单。我错过了什么吗? Rails 3 有什么不同吗?

最佳答案

在我看来还不错。它在 Rails 3 中非常相似,尽管默认情况下 session 配置存储在 config/initializers/session_store.rb 中。我通常调整我的看起来像......

MyApp::Application.config.session_store :cookie_store, :key => '_my_app_session',
                                                       :secure => Rails.env == 'production', # Only send cookie over SSL when in production mode
                                                       :httponly => true, # Don't allow Javascript to access the cookie (mitigates cookie-based XSS exploits)
                                                       :expire_after => 60.minutes

secret 保存在 config/initializers/secret_token.rb 中:
MyApp::Application.config.secret_token = 'secret secrets are no fun...'

如果您有权访问您的 Apache(或其他)配置,您还可以在该级别强制使用 SSL。让我觉得这是一个更合适的地方,但我想不是每个人都有这个选择。

关于ruby-on-rails - 如何保护 Rails 应用程序免受 Firesheep 攻击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4147387/

相关文章:

security - 限制用户在 (HA) 代理上的 SSH 访问

security - 使用 keytool 生成 key 和证书

c# - 在运行时更改成员身份提供程序 ApplicationName。如何?

node.js - 我可以将 npm node_modules 目录放在我的 'webroot' 之外吗

css - Bootstrap 危险类不适用于表行

ruby-on-rails - OpenSSL::SSL::SSLError: 主机名 "freegeoip.io"与 ruby​​ geocoder gem 中的服务器证书不匹配

ruby-on-rails - rails : Modifying a Model Generated by Scaffolding

swift - NSSecureCoding 与钥匙串(keychain)

ruby-on-rails - 在同一 View RoR 中的表单之间传递参数

ruby-on-rails - 如何配置额外的/不同的迁移文件夹