How can I make cookies secure (https-only) by default in rails?

后端 未结 8 1881
不知归路
不知归路 2021-02-01 14:34

In a Rails controller, I can set a cookie like this:

cookies[:foo] = \"bar\"

And specify that the \"secure\" (https-only) flag be on like this:

相关标签:
8条回答
  • 2021-02-01 15:22

    You should look at the rack-ssl-enforcer gem. I was just looking for a clean answer to this and it solves the problem independent of which version of Rails you're on, plus it's extremely configurable.

    0 讨论(0)
  • 2021-02-01 15:26
    # session only available over HTTPS
    ActionController::Base.session_options[:secure] = true
    
    0 讨论(0)
提交回复
热议问题