Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invalidate specific session at logout in Rails /w Devise?

I want to invalidate the session when a user logs out using Devise, i have a callback to catch when a user logs out, for more protection against session hijacking.

class ApplicationController < ActionController::Base
  def sign_out(*args)
    super(*args)
    reset_session
  end
end

My understanding was that this would remove the session info stored on the server side, therefore invalidating it.

However I can still login using the session id I got before signing out. Am I misunderstanding how it works? I only want to invalidate just this session, not all of them.

I am using the default for session_store.

like image 820
Saifis Avatar asked Jul 22 '13 02:07

Saifis


People also ask

How can we make existing session be invalidated?

To invalidate a session manually, call the following method: session. invalidate(); All objects bound to the session are removed.

What does session invalidated mean?

Session invalidation means session destroying.So if session is destroyed,it indicates that server cant identify the client which has visited in previous.So now it creates a new session id for that client.


1 Answers

After some googling and meditating, I came apon this question, which could be modified to fit my needs,

all I did was

application_controller.rb

  def sign_out(*args)
    current_user.update_attribute(:current_sign_in_token, "")
    super
  end

which will invalidate the sign_in_token, thus invalidating the session, so hijacking the session id will still get you kicked out.

like image 153
Saifis Avatar answered Sep 22 '22 21:09

Saifis