Eventhough you can use sess_read to read and restore a users session (e.g. you come form a client without cookies ... Flash bug .. swfupload ) but you still have the session id posted by $_POST or something (services will also do that probably).
In that case, using sess_read(SID) will load the proper $user object, with the correct $user->sid . But session_id() is not set correctly, so e.g. form token validation fails (uses session_id, not $user->id).
Patch would be
--- includes/session.inc
+++ includes/session.inc
@@ -36,7 +36,8 @@ function sess_read($key) {
if ($user && $user->uid > 0 && $user->status == 1) {
// This is done to unserialize the data member of $user
$user = drupal_unpack($user);
-
+ // Set the internal PHP session_id. If thats out of sync, token validation will fail
+ session_id($user->sid);
Comments
Comment #1
eugenmayer commentedComment #2
EvanDonovan commented"Needs review" is only for bugs with a patch needing review. Setting to active.
Comment #3
eugenmayer commentedWell there is patch above? :)
Comment #4
eugenmayer commentedAttched the patch as "downloadable" file. Told it gets ignore otherwise. Whatever suits you master ..
Comment #6
eugenmayer commentedPatch is against 6.x not 7.x
Comment #7
dawehnerThis bug should be first fixed in d7. Let's see first what the testbot says. I guess a simpletest could help here, too :)
Comment #8
dawehner#4: session.inc_.patch queued for re-testing.
Comment #10
dawehnerRerole for d7
Comment #11
eugenmayer commentedThanks daniel. So i guess the procedure will be to implement it in D7 and backport my patch back to d6, or?
Comment #12
dawehnerYes, i think thats the default patch behavior.
Comment #13
damien tournoud commentedI fail to see where the "critical bug" is here. Someone calling a *private* core function directly is not something we want or need to support.
Also, marking as
needs work, because supposing we want to do that, the code is not correct: the correct session identifier to use depends on HTTP vs HTTPS.Comment #14
damien tournoud commentedIf we want to implement that as a feature request, I suggest adding a function that simply sets
$_COOKIE[session_name()]and callsdrupal_session_initialize().Comment #15
eugenmayer commentedWell, this method is supposed to restore the session out of the DB. And it takes one argument, the session-id. It restores the session, but it fails to check to set the session_id, so half of the system works, half not.
If we have our own session-handler, we need to take care of this, and i defently see that as a bug. As internal session id and the "oftern used" session ($user->sid) are not in sync and therefor causes confusion.
Setting back to old status - not marking critical thought - you are right that this does not affect a lot of env.
Comment #16
eugenmayer commentedTitle..
Comment #17
damien tournoud commentedSorry, but you are *not* supposed to call a function explicitly marked as private. _drupal_session_read()/sess_read() are supposed to be called from PHP only.
And again, you probably don't even have to, I guess that simply doing this should work:
Refer to the PHP documentation for proper use of the session API. Calling a private API function of Drupal doesn't qualify as "proper use".
Comment #18
eugenmayer commentedI really have no motivation argueing here. Private function yes or now. The "private" function does not what it is designed for - it is simply incomplete.
Do what you want
Comment #19
damien tournoud commentedOn the contrary, _drupal_session_read()/sess_read() do exactly what they are designed for: being registered as PHP "read" session callbacks.
See http://php.net/manual/en/function.session-set-save-handler.php for the documentation and example of those callbacks. You will see that *none of them* call session_id(), that's just not what they are designed for.