Rails 2.3引入的防止跨站攻击的功能在某些情况下会导致用户正常使用时也产生InvalidAuthenticityToken异常,比如某个表单需要登录后才能提交,但是用户在登录后,过了很长一段时间才提交,此时Session已经失效,就会导致这个异常,有些人会直接忽略验证AuthenticityToken的filter,但是这样有安全隐患,比较好的处理方法就是在ApplicationController中增加一个全局Handler: class ApplicationController < ActionController::Base &nsp; rescue_from ActionController::InvalidAuthenticityToken, :with => :bad_token def bad_token flash[:notice] = “Your session has expired.” respond_to do |accepts| accepts.html do store_location redirect_to(:controller => ‘/sessions’, :action => ‘new’) and return false end accepts.js do store_location render :update do |page| page.redirect_to(:controller => ‘/sessions’, :action => ‘new’) and return false end end end end [...]
Twitter Updates
- 我厌烦的5种创业想法: 我听到许多人新的创业想法,尽管这很不错,然而我开始反复听到一些相同的创意。 发现你周围的人的应用 - 没人想找到他们周围的人并和他们见面。相信我。这很奇怪,并且早就有这样的应用了。我不知道为什么人们会... http://t.co/mXdjeCZN 3 days ago
- 脏代码技巧 精准补丁(外二则): 精准补丁 有个老笑话是这么说的: 病人:“医生,我一这样就难受。” 医生:“那就别那样。” 有趣,但把它用在自己的项目中也管用吗?这让我想起了自己从PC移植一款3D第三人称射击游戏到初代... http://t.co/AAa7ju2g 2011-12-02
- @mine260309 额,没有吧,我这貌似可以正常访问 in reply to mine260309 2011-12-01
- More updates...
Posting tweet...
Powered by Twitter Tools
-
Recent Posts
订阅
