2015-03-19 59 views

回答

7

Rails的3/4

如果你想标记的会话cookie的安全,在config/initializers/session_store.rb,设置安全标志:

Demo::Application.config.session_store :cookie_store, 
    key: '_demo_session', 
    secret: "your secret", 
    secure: Rails.env.production?, # flags cookies as secure only in production 
    httponly: true # should be true by default for all cookies 

如果你想旗所有饼干一样安全在所需的config/environments/*.rb文件中添加config.force_ssl = true。该功能为您的Rails应用程序添加了其他功能,总结为here

+0

@Srinivas Yadav我还创建了一个极简主义的机架中间件,您可以用它来设置所有会话cookie上的安全标志:https://github.com/jmera/secure_cookies – jmera 2015-07-11 16:23:16

+0

'config.force_ssl = true'除非你做通过您的负载平衡器SSL – Tilo 2017-03-30 00:20:09