Skip to content

Commit 0d971eb

Browse files
committed
bug #60350 [Security][LoginLink] Throw InvalidLoginLinkException on invalid parameters (davidszkiba)
This PR was merged into the 6.4 branch. Discussion ---------- [Security][LoginLink] Throw `InvalidLoginLinkException` on invalid parameters | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60347 | License | MIT With this change, in addition to checking the presence of the required request parameters, also the type is checked. Commits ------- 0dc4d0b [Security][LoginLink] Throw InvalidLoginLinkException on invalid parameters
2 parents 0069734 + 0dc4d0b commit 0d971eb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Symfony/Component/Security/Http/LoginLink/LoginLinkHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ public function consumeLoginLink(Request $request): UserInterface
8686
if (!$hash = $request->get('hash')) {
8787
throw new InvalidLoginLinkException('Missing "hash" parameter.');
8888
}
89+
if (!is_string($hash)) {
90+
throw new InvalidLoginLinkException('Invalid "hash" parameter.');
91+
}
92+
8993
if (!$expires = $request->get('expires')) {
9094
throw new InvalidLoginLinkException('Missing "expires" parameter.');
9195
}
96+
if (preg_match('/^\d+$/', $expires) !== 1) {
97+
throw new InvalidLoginLinkException('Invalid "expires" parameter.');
98+
}
9299

93100
try {
94101
$this->signatureHasher->acceptSignatureHash($userIdentifier, $expires, $hash);

src/Symfony/Component/Security/Http/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)