Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

No way to flush session data to session store immidiately enables race conditions to occur

#2174

Following code demonstrates race condition in session handling:


def action_that_should_be_called_only_once_per_session
  my_custom_lock_for_current_session do
    # Critical section
    @account.total_cash += session[:income]
    session.delete :income
  end
  # Race condition window from now to the moment when the session is stored.
  # User can refresh the page and increase @account.total_cash.
end

There should be a way to forcefully save session data to session store (with the obvious exception of cookie store). This way, calling (let's say) store_session() from within critical section will prevent above vulnerability.

In PHP there is session_write_close() which does similiar thing as described.

Reported by Pawel · March 8th, 2009 @ 11:34 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. foospam (at o2)
    foospam (at o2)

    "I wonder why this ticket is not marked with security tag. This is an old problem with Rails and it should be fixed, but as now Rails handles sessions thru Rack I don't know where it belongs - to Rails or to Rack?"

    March 15th, 2009 @ 08:11 PM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. David Trasbo
    David Trasbo
    • Importance changed from to

    The Memcache and cookie stores exists in Rack, ActiveRecord::SessionStore still lives inside Rails. Rails still implements an AbstractStore class, though, that it uses for the Active Record store. I don't know if Rails magically makes the two session stores that lives in Rack inherit from that class, or something. Maybe it has to fixed both in Rails and Rack.

    August 1st, 2010 @ 06:39 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:34 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:34 PM