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

后端 未结 8 1883
不知归路
不知归路 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:00

    starting with rails 3.1, according to the rails security guide, you can simply set the following in your application.rb:

    config.force_ssl = true
    

    this forces the cookie to be sent over https only (and I assume everything else, too).

提交回复
热议问题