Skip to content

Commit 2888e40

Browse files
committed
bug symfony#41910 [Security] Handle concurency in Csrf DoctrineTokenProvider (jderusse)
This PR was merged into the 5.3 branch. Discussion ---------- [Security] Handle concurency in Csrf DoctrineTokenProvider | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When the `PersistentRememberMeHandler` class process a `RememberMe` cookie older than 1 minute it can tells the `tokenVerifier` to update it. This method performs a `delete` then an `insert`. This could be an issue with concurrent requests leading to `UniqueConstraintViolationException`. This PR wrap the delete/insert in a transaction to prevent this. Commits ------- c35eb75 Handle concurency in Csrf DoctrineTokenProvider
2 parents e1c020a + c35eb75 commit 2888e40

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ public function updateExistingToken(PersistentTokenInterface $token, string $tok
192192
return;
193193
}
194194

195-
$this->deleteTokenBySeries($tmpSeries);
196-
$this->createNewToken(new PersistentToken($token->getClass(), $token->getUserIdentifier(), $tmpSeries, $token->getTokenValue(), $lastUsed));
195+
$this->conn->beginTransaction();
196+
try {
197+
$this->deleteTokenBySeries($tmpSeries);
198+
$this->createNewToken(new PersistentToken($token->getClass(), $token->getUserIdentifier(), $tmpSeries, $token->getTokenValue(), $lastUsed));
199+
200+
$this->conn->commit();
201+
} catch (\Exception $e) {
202+
$this->conn->rollBack();
203+
}
197204
}
198205

199206
/**

0 commit comments

Comments
 (0)