This is notno security hole, butit's the custom code that you have shared.
// When you load the global user object ...
global $user;
// And... and then assign andanother user object to the global $user object ...
$user = user_load(<any_uid>);
// ... Drupal basically changechanges the context of the current user.
// ItsIt's kind of a hacky login by code.
// Hacky because, till this code executes.
// There isthere's no log about the user login, untilluntil drupal writes the current session ininto the database.
$user
Typically $account
is advised to prevent accidents like this.
$account = user_load(<any_uid>);