2015-03-19 65 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