Skip to content

Commit

Permalink
Avoid error if token is not string
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Jan 27, 2025
1 parent 736bfcf commit adb32e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/AntiCSRF.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public function generateToken() : string
*/
public function getUserToken() : ?string
{
return $this->request->getParsedBody($this->getTokenName());
$token = $this->request->getParsedBody($this->getTokenName());
return \is_string($token) ? $token : null;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/AntiCSRFTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ public function testUserTokenEmpty() : void
self::assertFalse($this->anti->verify());
}

public function testUserTokenIsNotString() : void
{
$this->prepare();
$_POST = [
'csrf_token' => [
'foo' => 'bar',
],
];
self::assertFalse($this->anti->verify());
}

public function testVerifySuccess() : void
{
$this->prepare();
Expand Down

0 comments on commit adb32e8

Please sign in to comment.