Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store user session if it has not already been initialized #1293

Closed
wants to merge 1 commit into from

Conversation

aschempp
Copy link
Member

@aschempp aschempp commented Jan 8, 2018

see #1288

@leofeyer
Copy link
Member

leofeyer commented Jan 8, 2018

I am pretty sure that the fix is wrong.

$user = $token->getUser();
if (!$user instanceof User) {
return;
}
$session = $user->session;

The user object is incomplete upon login, because it has not been created via User::loadUserByUsername() but via User::unserialize(). That's why $user->session is empty.

  • My approach ensures that $user->session is set upon login.

  • Your approach ensures that the empty session is not stored in the database.

So in your approach, the session will be empty for the login request! And we don't know if there are other listeners (e.g. storing the referer) that also rely on the session not being empty?

@leofeyer leofeyer added the bug label Jan 8, 2018
@leofeyer leofeyer added this to the 4.5.2 milestone Jan 8, 2018
@aschempp
Copy link
Member Author

aschempp commented Jan 8, 2018

The user object is incomplete upon login, because it has not been created via User::loadUserByUsername() but via User::unserialize().

This cannot be true. First of all, the login process obviously does not have a token in the session, otherwise a login would not be required. So there is nothing to be unserialized or incomplete. On subsequent requests the user is unserialized from the session, but the refreshUser method will fetch the database object again before the firewall is successful.

@leofeyer
Copy link
Member

leofeyer commented Jan 9, 2018

I have dumped the user object in line 86:

Array
(
    [id] => 1
    [tstamp] => 1514978172
    [username] => k.jones
    [name] => Kevin Jones
    [email] => k.jones@example.com
    [language] => de
    [backendTheme] => flexible
    [uploader] => FileUpload
    [showHelp] => 1
    [thumbnails] => 1
    [useRTE] => 1
    [useCE] => 1
    [password] => $2y$10$mASa6zAiFYfIWirQbLepx.q5B4t52o9KU8NwOIGBY6mfF6..emjbK
    [pwChange] => 
    [admin] => 1
    [groups] => 
    [inherit] => 
    [modules] => 
    [themes] => 
    [pagemounts] => Array
        (
        )

    [alpty] => 
    [filemounts] => Array
        (
            [0] => a:0:{}
        )

    [fop] => 
    [forms] => 
    [formp] => 
    [disable] => 
    [start] => 
    [stop] => 
    [session] => Array
        (
        )

    [dateAdded] => 1257428510
    [lastLogin] => 1515481605
    [currentLogin] => 1515481617
    [loginCount] => 3
    [locked] => 0
    [calendars] => 
    [calendarp] => 
    [calendarfeeds] => 
    [calendarfeedp] => 
    [news] => 
    [newp] => 
    [newsfeeds] => 
    [newsfeedp] => 
    [newsletters] => 
    [newsletterp] => 
    [faqs] => 
    [faqp] => 
    [imageSizes] => 
    [amg] => 
    [fullscreen] => 
)

You are right that the object is not incomplete (e.g. dateAdded is not serialized). But why is there no session data then?

@aschempp
Copy link
Member Author

aschempp commented Jan 9, 2018

Maybe the session data is simply not unserialized?

@leofeyer
Copy link
Member

leofeyer commented Jan 9, 2018

The session data is never serialized so it cannot be unserialized, can it?

@aschempp
Copy link
Member Author

aschempp commented Jan 9, 2018

It sure is serialized, tl_user.session is a database field?

@leofeyer
Copy link
Member

leofeyer commented Jan 9, 2018

I'm talking about this:

public function serialize()
{
return serialize(array($this->id, $this->username, $this->disable, $this->admin, $this->groups));
}

@leofeyer
Copy link
Member

I have added the changes (with unit test) in 5a721c6. Although it works, I don't like that the listener is now stateful. Is this ok for us?

@aschempp
Copy link
Member Author

The only other option I can think of is to only register the kernel.response event if kernel.request is called. That's how the firewall works (e.g. ContextListener).

@leofeyer
Copy link
Member

Brilliant. Changed in 82b22c9.

@leofeyer leofeyer closed this Jan 10, 2018
@leofeyer leofeyer self-assigned this Jan 10, 2018
@aschempp aschempp deleted the bugfix/user-session branch February 18, 2018 17:42
@leofeyer leofeyer modified the milestones: 4.5.2, 4.5 May 14, 2019
leofeyer added a commit that referenced this pull request Feb 7, 2020
Description
-----------

Fixes #1143

Commits
-------

f32dcb63 Update the back end keyboard shortcuts link (fixes #1143)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants