Skip to content

Commit 30b3bf7

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: properly skip signal test if the pcntl extension is not installed ensure that all supported e-mail validation modes can be configured [Security][LoginLink] Throw InvalidLoginLinkException on invalid parameters don't hardcode OS-depending constant values
2 parents 0a29c89 + 66768ba commit 30b3bf7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

LoginLink/LoginLinkHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ public function consumeLoginLink(Request $request): UserInterface
8484
if (!$hash = $request->get('hash')) {
8585
throw new InvalidLoginLinkException('Missing "hash" parameter.');
8686
}
87+
if (!is_string($hash)) {
88+
throw new InvalidLoginLinkException('Invalid "hash" parameter.');
89+
}
90+
8791
if (!$expires = $request->get('expires')) {
8892
throw new InvalidLoginLinkException('Missing "expires" parameter.');
8993
}
94+
if (preg_match('/^\d+$/', $expires) !== 1) {
95+
throw new InvalidLoginLinkException('Invalid "expires" parameter.');
96+
}
9097

9198
try {
9299
$this->signatureHasher->acceptSignatureHash($userIdentifier, $expires, $hash);

Tests/LoginLink/LoginLinkHandlerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,30 @@ public function testConsumeLoginLinkWithMissingExpiration()
240240
$linker->consumeLoginLink($request);
241241
}
242242

243+
public function testConsumeLoginLinkWithInvalidExpiration()
244+
{
245+
$user = new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash');
246+
$this->userProvider->createUser($user);
247+
248+
$this->expectException(InvalidLoginLinkException::class);
249+
$request = Request::create('/login/verify?user=weaverryan&hash=thehash&expires=%E2%80%AA1000000000%E2%80%AC');
250+
251+
$linker = $this->createLinker();
252+
$linker->consumeLoginLink($request);
253+
}
254+
255+
public function testConsumeLoginLinkWithInvalidHash()
256+
{
257+
$user = new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash');
258+
$this->userProvider->createUser($user);
259+
260+
$this->expectException(InvalidLoginLinkException::class);
261+
$request = Request::create('/login/verify?user=weaverryan&hash[]=an&hash[]=array&expires=1000000000');
262+
263+
$linker = $this->createLinker();
264+
$linker->consumeLoginLink($request);
265+
}
266+
243267
private function createSignatureHash(string $username, int $expires, array $extraFields = ['emailProperty' => 'ryan@symfonycasts.com', 'passwordProperty' => 'pwhash']): string
244268
{
245269
$hasher = new SignatureHasher($this->propertyAccessor, array_keys($extraFields), 's3cret');

0 commit comments

Comments
 (0)