Skip to content

Commit d7d9bee

Browse files
committed
CookieStorage: added MIN_LENGTH for UID
1 parent b0db780 commit d7d9bee

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Bridges/SecurityHttp/CookieStorage.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ final class CookieStorage implements Nette\Security\UserStorage
2121
{
2222
use Nette\SmartObject;
2323

24+
private const MIN_LENGTH = 13;
25+
2426
/** @var Http\IRequest */
2527
private $request;
2628

@@ -49,9 +51,13 @@ public function __construct(Http\IRequest $request, Http\IResponse $response)
4951

5052
public function saveAuthentication(IIdentity $identity): void
5153
{
54+
$uid = (string) $identity->getId();
55+
if (strlen($uid) < self::MIN_LENGTH) {
56+
throw new \LogicException('UID is too short.');
57+
}
5258
$this->response->setCookie(
5359
$this->cookieName,
54-
$identity->getId(),
60+
$uid,
5561
$this->cookieExpiration,
5662
null,
5763
$this->cookieDomain
@@ -72,7 +78,7 @@ public function clearAuthentication(bool $clearIdentity): void
7278
public function getState(): array
7379
{
7480
$uid = $this->request->getCookie($this->cookieName);
75-
$identity = is_string($uid)
81+
$identity = is_string($uid) && strlen($uid) >= self::MIN_LENGTH
7682
? new Nette\Security\SimpleIdentity($uid)
7783
: null;
7884
return [(bool) $identity, $identity, null];

0 commit comments

Comments
 (0)