Skip to content

Commit 34dfdf3

Browse files
alamiraultnicolas-grekas
authored andcommitted
[Security] Improve DX when invalid custom authenticators
1 parent 9ddffe9 commit 34dfdf3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Authentication/AuthenticatorManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function supports(Request $request): ?bool
104104
foreach ($this->authenticators as $authenticator) {
105105
$this->logger?->debug('Checking support on authenticator.', ['firewall_name' => $this->firewallName, 'authenticator' => $authenticator::class]);
106106

107+
if (!$authenticator instanceof AuthenticatorInterface) {
108+
throw new \InvalidArgumentException(sprintf('Authenticator "%s" must implement "%s".', get_debug_type($authenticator), AuthenticatorInterface::class));
109+
}
110+
107111
if (false !== $supports = $authenticator->supports($request)) {
108112
$authenticators[] = $authenticator;
109113
$lazy = $lazy && null === $supports;

Tests/Authentication/AuthenticatorManagerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public static function provideSupportsData()
7777
yield [[], false];
7878
}
7979

80+
public function testSupportsInvalidAuthenticator()
81+
{
82+
$manager = $this->createManager([new \stdClass()]);
83+
84+
$this->expectExceptionObject(
85+
new \InvalidArgumentException('Authenticator "stdClass" must implement "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface".')
86+
);
87+
88+
$manager->supports($this->request);
89+
}
90+
8091
public function testSupportCheckedUponRequestAuthentication()
8192
{
8293
// the attribute stores the supported authenticators, returning false now

0 commit comments

Comments
 (0)