Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  [Notifier] Fix markdown
  Update PR template
  Bump Symfony version to 5.4.17
  Update VERSION for 5.4.16
  Update CHANGELOG for 5.4.16
  Update VERSION for 4.4.49
  Update CONTRIBUTORS for 4.4.49
  Update CHANGELOG for 4.4.49
  [Security][LoginLink] Throw InvalidLoginLinkException on missing parameter
  • Loading branch information
nicolas-grekas committed Nov 30, 2022
2 parents 9531d2d + 863d398 commit feeeebb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions LoginLink/LoginLinkHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ public function consumeLoginLink(Request $request): UserInterface
throw new InvalidLoginLinkException('User not found.', 0, $exception);
}

$hash = $request->get('hash');
$expires = $request->get('expires');
if (!$hash = $request->get('hash')) {
throw new InvalidLoginLinkException('Missing "hash" parameter.');
}
if (!$expires = $request->get('expires')) {
throw new InvalidLoginLinkException('Missing "expires" parameter.');
}

try {
$this->signatureHasher->verifySignatureHash($user, $expires, $hash);
Expand Down
24 changes: 24 additions & 0 deletions Tests/LoginLink/LoginLinkHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ public function testConsumeLoginLinkExceedsMaxUsage()
$linker->consumeLoginLink($request);
}

public function testConsumeLoginLinkWithMissingHash()
{
$user = new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash');
$this->userProvider->createUser($user);

$this->expectException(InvalidLoginLinkException::class);
$request = Request::create('/login/verify?user=weaverryan&expires=10000');

$linker = $this->createLinker();
$linker->consumeLoginLink($request);
}

public function testConsumeLoginLinkWithMissingExpiration()
{
$user = new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash');
$this->userProvider->createUser($user);

$this->expectException(InvalidLoginLinkException::class);
$request = Request::create('/login/verify?user=weaverryan&hash=thehash');

$linker = $this->createLinker();
$linker->consumeLoginLink($request);
}

private function createSignatureHash(string $username, int $expires, array $extraFields): string
{
$fields = [base64_encode($username), $expires];
Expand Down

0 comments on commit feeeebb

Please sign in to comment.