4
我有Rails应用程序,它在https上运行。 我的应用程序会话cookie仅为http。 如何将这些cookie设置为安全且只在https中使用https?将会话cookie设置为安全的导轨
我有Rails应用程序,它在https上运行。 我的应用程序会话cookie仅为http。 如何将这些cookie设置为安全且只在https中使用https?将会话cookie设置为安全的导轨
如果你想标记的会话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。
@Srinivas Yadav我还创建了一个极简主义的机架中间件,您可以用它来设置所有会话cookie上的安全标志:https://github.com/jmera/secure_cookies – jmera 2015-07-11 16:23:16
'config.force_ssl = true'除非你做通过您的负载平衡器SSL – Tilo 2017-03-30 00:20:09