Lau*_*ung 32 ruby ruby-on-rails
保护您的Cookies页面:HttpOnly解释了为什么制作HttpOnly cookie是一个好主意.
如何在Ruby on Rails中设置此属性?
Lau*_*ung 32
在用于设置cookie的哈希中设置'http_only'选项
例如
cookies["user_name"] = { :value => "david", :httponly => true }
或者,在Rails 2中:
例如
cookies["user_name"] = { :value => "david", :http_only => true }
jim*_*jim 12
Re Laurie的回答:
请注意,该选项在某些时候已重命名:http_only
为:httponly
(无下划线).
在actionpack 3.0.0中,即Ruby on Rails 3,所有引用:http_only
都消失了.
那让我感动了一阵子.
如果您\xe2\x80\x99 有一个名为 config/session_store.rb 的文件,其中包含此行(Rails 3+),则它\xe2\x80\x99s 已自动设置。\n config/initializers/session_store.rb
:
# Be sure to restart your server when you modify this file.\nRails.application.config.session_store :cookie_store, key: "_my_application_session"\n
Run Code Online (Sandbox Code Playgroud)\n\nRails 还允许您设置以下键:
\n\n:expires -此 cookie 过期的时间,作为 Time 对象。
\n\n:secure -此 cookie 是否仅传输到 HTTPS 服务器。默认为 false。
\n 归档时间: |
|
查看次数: |
10374 次 |
最近记录: |