English 中文(简体)
铁路( set_no_cache 方法) 无法禁用Safari 和 Opera 中的浏览器缓存
原标题:Rails ( set_no_cache method) Cannot disable browser caching in Safari and Opera

使用 Devise 来验证我的认证后, 我发现有一个安全漏洞, 在用户登录退出后, 会话变量会被保存。 这样任何人都可以按下后键并访问用户前一个屏幕中登录的 。

I looked at these posts Num 1 Num 2 Num 3

我把这些线条加到我的应用程序控制器上

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中,不安全行为依然存在。这个代码没有效果。

关于如何解决这个问题,有什么建议吗?

谢谢 谢谢

最佳回答

我面对同样的问题,找到了一个好的解决办法,我用博客把它写到

http://www.fordevs.com/2011/10/how-to-revention-browser-from-caching-a-page-in-rails.html>http://www.fordfs.com/2011/10/how-to-revention-browser-from-caching-a-page-in-rails.html

要添加“ no-cache”,请添加以下行@ application_ controller.rb 文件

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
问题回答

首先,对于与缓存有关的任何问题,请使用 Mark Nottingham s < a href="http://www.mnot.net/cache_docs/" rel=“nofollow” > 指南 HTTP caching

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

试试这个

我发现在我的应用程序控制器里这样做 对发展很有帮助

after_filter  :expire_for_development

protected

def expire_for_development
  expires_now if Rails.env.development?
end




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签