Skip to content

Commit 5383794

Browse files
committed
Avoid error if token is not string
1 parent 148cb9e commit 5383794

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/AntiCSRF.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public function setToken(?string $token = null) : static
100100
*/
101101
public function getUserToken() : ?string
102102
{
103-
return $this->request->getParsedBody($this->getTokenName());
103+
$token = $this->request->getParsedBody($this->getTokenName());
104+
return \is_string($token) ? $token : null;
104105
}
105106

106107
/**

tests/AntiCSRFTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public function testUserTokenEmpty() : void
7676
self::assertFalse($this->anti->verify());
7777
}
7878

79+
public function testUserTokenIsNotString() : void
80+
{
81+
$this->prepare();
82+
$_POST = [
83+
'csrf_token' => [
84+
'foo' => 'bar',
85+
],
86+
];
87+
self::assertFalse($this->anti->verify());
88+
}
89+
7990
public function testVerifySuccess() : void
8091
{
8192
$this->prepare();

0 commit comments

Comments
 (0)