Skip to content

Commit adb32e8

Browse files
committed
Avoid error if token is not string
1 parent 736bfcf commit adb32e8

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
@@ -162,7 +162,8 @@ public function generateToken() : string
162162
*/
163163
public function getUserToken() : ?string
164164
{
165-
return $this->request->getParsedBody($this->getTokenName());
165+
$token = $this->request->getParsedBody($this->getTokenName());
166+
return \is_string($token) ? $token : null;
166167
}
167168

168169
/**

tests/AntiCSRFTest.php

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

155+
public function testUserTokenIsNotString() : void
156+
{
157+
$this->prepare();
158+
$_POST = [
159+
'csrf_token' => [
160+
'foo' => 'bar',
161+
],
162+
];
163+
self::assertFalse($this->anti->verify());
164+
}
165+
155166
public function testVerifySuccess() : void
156167
{
157168
$this->prepare();

0 commit comments

Comments
 (0)