TypeError: Drupal\user\UserAuthentication::authenticateAccount(): Argument #1 (closed) ($account) must be of type Drupal\user\UserInterface, bool given

Created on 18 November 2024, 8 months ago

Problem/Motivation

We get the following exception with the NamePassword plugin since we've updated to 3.1:

TypeError: Drupal\user\UserAuthentication::authenticateAccount(): Argument #1 ($account) must be of type Drupal\user\UserInterface, bool given, called in /var/www/html/web/modules/contrib/security_review/src/Plugin/SecurityCheck/NamePasswords.php on line 99 in Drupal\user\UserAuthentication->authenticateAccount() (line 76 of /var/www/html/web/core/modules/user/src/UserAuthentication.php).

#0 /var/www/html/web/modules/contrib/security_review/src/Plugin/SecurityCheck/NamePasswords.php(99): Drupal\user\UserAuthentication->authenticateAccount(false, Object(SensitiveParameterValue))
#1 /var/www/html/web/modules/contrib/security_review/src/SecurityReview.php(119): Drupal\security_review\Plugin\SecurityCheck\NamePasswords->run(true, Array)
#2 /var/www/html/web/modules/contrib/drd_agent/src/Agent/Remote/SecurityReview.php(37): Drupal\security_review\SecurityReview->runChecks(Array)
#3 /var/www/html/web/modules/contrib/drd_agent/src/Agent/Action/Info.php(26): Drupal\drd_agent\Agent\Remote\SecurityReview->collect()
#4 /var/www/html/web/modules/contrib/drd_agent/src/Agent/Action/Base.php(341): Drupal\drd_agent\Agent\Action\Info->execute()
#5 /var/www/html/web/modules/contrib/drd_agent/src/Controller/Agent.php(79): Drupal\drd_agent\Agent\Action\Base->run(false)
#6 [internal function]: Drupal\drd_agent\Controller\Agent->get()
#7 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/modules/contrib/crowdsec/src/Middleware.php(96): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\crowdsec\Middleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#27 {main}

Proposed resolution

There seem to be 2 things that need fixing:

  • As $this->userAuth->lookupAccount either returns a UserInterface or FALSE, but $this->userAuth->authenticateAccount requires a UserInterface, it needs to be checked first, if the first method returns the correct type.
  • Using $user->getDisplayName() should be replaced by $user->getAccountName() as that's the identifier while the display name could be altered.
🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

🇩🇪Germany jurgenhaas Gottmadingen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024