Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird session issue with Rails 3 reset_session and cookies.delete(...) in the same controller action
    primarykey
    data
    text
    <p>In my logout action I'm doing this:</p> <pre><code>reset_session cookies.delete(:rememberme) redirect_to root_url </code></pre> <p>But the session is not being destroyed.</p> <p>When I inspect the headers, the request sent to my logout action clearly includes the session ID:</p> <pre><code>Cookie: hiddenalerts=site_vrfy_124258; __utmz=REMOVED_INFO.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); elpriv=REMOVED_INFO; SESSID=b39a9a89bb6a39ea91b620fe0da392ed; __utma=REMOVED_INFO; __utmc=REMOVED_INFO; __utmb=REMOVED_INFO </code></pre> <p>But the response only clears the rememberme cookie, it doesn't clear the session cookie:</p> <pre><code>Set-Cookie: rememberme=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT </code></pre> <p>If I compare this with the same headers when I comment out the rememberme cookie deletion. The request looks the same:</p> <pre><code>Cookie: hiddenalerts=site_vrfy_124258; __utmz=REMOVED_INFO.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); elpriv=REMOVED_INFO; SESSID=b39a9a89bb6a39ea91b620fe0da392ed; __utma=REMOVED_INFO; __utmc=REMOVED_INFO; __utmb=REMOVED_INFO </code></pre> <p>But the response looks more like I'd expect (and my session is correctly destroyed):</p> <pre><code>Set-Cookie: SESSID=50640523cf32b5b0fe8c93eb16aba6dc; path=/; HttpOnly </code></pre> <p>Has anyone else experienced this? I can only assume that the session handler and the ApplicationController don't hold the same reference to the cookies, so if you modify the cookies in the controller this clobbers anything that reset_session has done. I can work around this problem by manually deleting the session cookie, but I'd like to understand what's happening and if there's a known workaround first.</p> <p>Obviously I need the ability to clear a "remember me" cookie during the logout process, otherwise the user will simply be immediately logged back in.</p> <p>EDIT | Issue raised as a bug. I'll work around it for now. <a href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6763-deleting-a-cookie-and-calling-reset_session-in-the-same-controller-action-does-not-send-new-session-cookie" rel="nofollow">https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6763-deleting-a-cookie-and-calling-reset_session-in-the-same-controller-action-does-not-send-new-session-cookie</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload