8000 [Form] CsrfValidationListener marks the token as invalid if it is not… · symfony/symfony@deb8e95 · GitHub
[go: up one dir, main page]

Skip to content

Commit deb8e95

Browse files
umpirskynicolas-grekas
authored andcommitted
[Form] CsrfValidationListener marks the token as invalid if it is not a string
1 parent afb7bb5 commit deb8e95

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function preSubmit(FormEvent $event)
5959
if ($form->isRoot() && $form->getConfig()->getOption('compound') && !$postRequestSizeExceeded) {
6060
$data = $event->getData();
6161

62-
if (!isset($data[$this->fieldName]) || !$this->tokenManager->isTokenValid(new CsrfToken($this->tokenId, $data[$this->fieldName]))) {
62+
if (!isset($data[$this->fieldName]) || !\is_string($data[$this->fieldName]) || !$this->tokenManager->isTokenValid(new CsrfToken($this->tokenId, $data[$this->fieldName]))) {
6363
$errorMessage = $this->errorMessage;
6464

6565
if (null !== $this->translator) {

src/Symfony/Component/Form/Tests/Extension/Csrf/EventListener/CsrfValidationListenerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public function testStringFormData()
6464
$this->assertSame($data, $event->getData());
6565
}
6666

67+
public function testArrayCsrfToken()
68+
{
69+
$event = new FormEvent($this->form, ['csrf' => []]);
70+
71+
$validation = new CsrfValidationListener('csrf', $this->tokenManager, 'unknown', 'Invalid.');
72+
$validation->preSubmit($event);
73+
74+
$this->assertNotEmpty($this->form->getErrors());
75+
}
76+
6777
public function testMaxPostSizeExceeded()
6878
{
6979
$serverParams = $this

0 commit comments

Comments
 (0)
0