Skip to content

Instantly share code, notes, and snippets.

@mataki
Created February 9, 2011 07:11

Revisions

  1. mataki created this gist Feb 9, 2011.
    20 changes: 20 additions & 0 deletions rails2311_csrf_path.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    module ActionController
    module RequestForgeryProtection
    protected
    def verify_authenticity_token
    verified_request? || handle_unverified_request
    end

    # Process logout
    def handle_unverified_request
    reset_session
    end

    def verified_request?
    !protect_against_forgery? ||
    request.get? ||
    form_authenticity_token == form_authenticity_param ||
    form_authenticity_token == request.headers['X-CSRF-Token']
    end
    end
    end