8000 Fixes issue #29882 · symfony/symfony@4986c26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4986c26

Browse files
committed
Fixes issue #29882
1 parent facbaa5 commit 4986c26

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ public function testStringFormData()
7474
$this->assertSame($data, $event->getData());
7575
}
7676

77+
/**
78+
* @see https://github.com/symfony/symfony/issues/29882
79+
*/
80+
public function testArrayCsrfToken()
81+
{
82+
$data = ['csrf' => []];
83+
$event = new FormEvent($this->form, $data);
84+
85+
$validation = new CsrfValidationListener('csrf', $this->tokenManager, 'unknown', 'Invalid.');
86+
$validation->preSubmit($event);
87+
88+
$this->assertNotEmpty($this->form->getErrors());
89+
}
90+
7791
public function testMaxPostSizeExceeded()
7892
{
7993
$serverParams = $this

0 commit comments

Comments
 (0)
0