Skip to content

Commit 0e6cbce

Browse files
fix: make TrustedDeviceTokenStorage conform to ResetInterface
In certain scenarios, TrustedDeviceTokenStorage might not be re-instanciated between requests. That's the case when multiple requests are handled by a single worker, like when serving the application with RoadRunner or with FrankenPHP. In that case, the trusted_device cookie leak from a request to another, and break the feature entirely. By implementing ResetInterface, the storage is now properly reseted between requests
1 parent e4bf04e commit 0e6cbce

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use RuntimeException;
88
use Symfony\Component\HttpFoundation\Request;
99
use Symfony\Component\HttpFoundation\RequestStack;
10+
use Symfony\Contracts\Service\ResetInterface;
1011
use function array_map;
1112
use function explode;
1213
use function implode;
1314

1415
/**
1516
* @final
1617
*/
17-
class TrustedDeviceTokenStorage
18+
class TrustedDeviceTokenStorage implements ResetInterface
1819
{
1920
private const TOKEN_DELIMITER = ';';
2021

@@ -100,6 +101,12 @@ public function clearTrustedToken(string $username, string $firewall): void
100101
$this->updateCookie = true;
101102
}
102103

104+
public function reset(): void
105+
{
106+
$this->updateCookie = false;
107+
$this->trustedTokenList = null;
108+
}
109+
103110
/**
104111
* @return TrustedDeviceToken[]
105112
*/

0 commit comments

Comments
 (0)