在使用Devise进行身份验证后,我发现有一个安全漏洞,在用户注销后,会话变量被保留。这允许任何人按下后退按钮并访问登录用户的上一屏幕。
我将这些行添加到application_controller中
before_filter :set_no_cache
def set_no_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
在_form.html.erb中,我在顶部添加了这个
<%if user_signed_in? %>
<%=link_to "Sign Out", destroy_user_session_path, :method => :delete %><br/>
<%= form_for(@listing) do |f| %>
<% if @listing.errors.any? %>
...........
然后我在Firefox,Chrome和Safari上测试了该应用程序。
Firefox和Chrome很好,因为我退出并点击了后退按钮,无法看到用户的上一个屏幕,但是,在Safari和Opera中,不安全的行为仍然存在。此代码没有效果。
对于如何解决这个问题,有任何的建议吗?
谢谢