Page MenuHomePhabricator

UserLoadFromSession considered evil
Closed, ResolvedPublic

Description

Running code from CentralAuth, AbuseFilter, TitleBlacklist etc. which collectively call half the codebase does not seem like a good thing to be doing while the main context user is half-initialised and has lots of methods which will fail horribly if you try to call them (e.g. T43198).

Perhaps initialisation of the User object from the session can be moved to a function called from Setup.php, such as RequestContext::getUser(). It's not lazy-loaded anyway, User::newFromSession() has always been called unconditionally. Then CentralAuth (and anything else that uses the UserLoadFromSession hook) can be called without User::load() in its call stack.


Version: unspecified
Severity: normal
See Also: T60731

Details

Reference
bz41201

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:01 AM
bzimport set Reference to bz41201.
bzimport added a subscriber: Unknown Object (MLST).

Looking at WMF-deployed extensions, I see that OAuth and CentralAuth use this hook.

OAuth checks the request's Title object to avoid running on Special:OAuth itself (Special:OAuth needs to do special stuff). To be able to call UserLoadFromSession in Setup.php, we'd either have to change this check or create Title in Setup.php too, before the $wgExtensionFunctions hooks.

CentralAuth doesn't seem to directly do anything that would blow up if called from Setup.php. But it might call the AbortAutoAccount and AuthPluginAutoCreate hooks, which might have the same sort of expectations of being called after Setup.php as OAuth.

mmodell raised the priority of this task from Medium to High.Feb 14 2015, 1:42 AM
mmodell subscribed.

priority: high because this is batshit insane and can't be justified.

Tgr subscribed.

AuthManager deprecates UserLoadFromSession. We'll see if the new code is less evil.

Coming up with documentation standards for "this method might be called in a pre-auth context" sounds like a good idea.

Tgr claimed this task.

Fixed a while ago in SessionManager; See Setup.php L715-780 and L833-843.