Lacking a $_COOKIE entry, sess_write will optimize out our nice, successful login -- which calls sess_regenerate so it seemed a nice place to move the cookie around. If something else calls this function, well, session_regenerate_id issues a new cookie so the $_COOKIE entry needs to be moved.

CommentFileSizeAuthor
#4 195553.diff930 bytesR.Muilwijk
#1 session.inc_.patch791 bytesdrumm
cookie_set_in_regen.patch783 byteschx

Comments

drumm’s picture

Title: Loggin in from an out-of-site form is not possible » Logging in from an out-of-site form is not possible
Version: 5.x-dev » 7.x-dev
StatusFileSize
new791 bytes

The same algorithm is present in HEAD, so it should get a proper review there before being backported. It took me a few minutes to figure out what exactly is happening, so I changed the second comment.

moshe weitzman’s picture

Seems reasonable. If it passes the tests, I think it is commit worthy.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

R.Muilwijk’s picture

Status: Needs work » Needs review
StatusFileSize
new930 bytes

Reroll to HEAD.

damien tournoud’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs review » Patch (to be ported)

D7 cannot be affected.

R.Muilwijk’s picture

Should it not go to drupal 8 then?

damien tournoud’s picture

@R.Muilwijk: no, I just meant that I don't believe this particular bug affects Drupal 7, because we completely refactored the session handling code.

R.Muilwijk’s picture

Well that is true but when looking at the code the regeneration is done exact the same as it was and needs the patch.

  if (drupal_session_started()) {
    $old_session_id = session_id();
    // Remove the old session cookie.
    unset($_COOKIE[session_name()]);
    session_regenerate_id();
  }
  else {
    // Start the session when it doesn't exist yet.
    // Preserve the logged in user, as it will be reset to anonymous
    // by _drupal_session_read.
    $account = $user;
    drupal_session_start();
    $user = $account;
  }

  if (isset($old_session_id)) {
    // Save the new session cookie for code which assumes it will be present,
    // such as sess_write().
    $_COOKIE[session_name()] = session_id();

    $fields = array('sid' => session_id());
    if ($is_https) {
      $fields['ssid'] = session_id();
      // If the "secure pages" setting is enabled, use the newly-created
      // insecure session identifier as the regenerated sid.
      if (variable_get('https', FALSE)) {
        $fields['sid'] = $session_id;
      }
    }
    db_update('sessions')
      ->fields($fields)
      ->condition($is_https ? 'ssid' : 'sid', $old_session_id)
      ->execute();
  }

Please correct me if I a wrong?

damien tournoud’s picture

_drupal_session_write doesn't optimize for the cookie-less case anymore, so we don't need the trick in the session regeneration code.

chx’s picture

Assigned: chx » Unassigned
Issue summary: View changes

Status: Patch (to be ported) » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.