Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0dc4d0b

Browse filesBrowse files
committed
[Security][LoginLink] Throw InvalidLoginLinkException on invalid parameters
1 parent 6b4f603 commit 0dc4d0b
Copy full SHA for 0dc4d0b

File tree

2 files changed

+31
-0
lines changed
Filter options

2 files changed

+31
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/LoginLink/LoginLinkHandler.php
+7Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/LoginLink/LoginLinkHandlerTest.php
+24Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.