Skip to content

Commit b12c621

Browse files
wouterjfabpot
authored andcommitted
[Security] Added check_post_only to the login link authenticator
1 parent 837e59c commit b12c621

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Authenticator/LoginLinkAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public function __construct(LoginLinkHandlerInterface $loginLinkHandler, HttpUti
4343
$this->httpUtils = $httpUtils;
4444
$this->successHandler = $successHandler;
4545
$this->failureHandler = $failureHandler;
46-
$this->options = $options;
46+
$this->options = $options + ['check_post_only' => false];
4747
}
4848

4949
public function supports(Request $request): ?bool
5050
{
51-
return $this->httpUtils->checkRequestPath($request, $this->options['check_route']);
51+
return ($this->options['check_post_only'] ? $request->isMethod('POST') : true)
52+
&& $this->httpUtils->checkRequestPath($request, $this->options['check_route']);
5253
}
5354

5455
public function authenticate(Request $request): PassportInterface
5556
{
5657
$username = $request->get('user');
57-
5858
if (!$username) {
5959
throw new InvalidLoginLinkAuthenticationException('Missing user from link.');
6060
}

Tests/Authenticator/LoginLinkAuthenticatorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ protected function setUp(): void
3939
$this->failureHandler = $this->createMock(AuthenticationFailureHandlerInterface::class);
4040
}
4141

42+
/**
43+
* @dataProvider provideSupportData
44+
*/
45+
public function testSupport(array $options, $request, bool $supported)
46+
{
47+
$this->setUpAuthenticator($options);
48+
49+
$this->assertEquals($supported, $this->authenticator->supports($request));
50+
}
51+
52+
public function provideSupportData()
53+
{
54+
yield [['check_route' => '/validate_link'], Request::create('/validate_link?hash=abc123'), true];
55+
yield [['check_route' => '/validate_link'], Request::create('/login?hash=abc123'), false];
56+
yield [['check_route' => '/validate_link', 'check_post_only' => true], Request::create('/validate_link?hash=abc123'), false];
57+
yield [['check_route' => '/validate_link', 'check_post_only' => true], Request::create('/validate_link?hash=abc123', 'POST'), true];
58+
}
59+
4260
public function testSuccessfulAuthenticate()
4361
{
4462
$this->setUpAuthenticator();

0 commit comments

Comments
 (0)