Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #212 from Saeven/master
Browse files Browse the repository at this point in the history
CSRF shouldn't throw PHP errors when it receives non-string input
  • Loading branch information
weierophinney committed Feb 1, 2018
2 parents b327118 + 9e13e74 commit c1bed80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public function __construct($options = [])
*/
public function isValid($value, $context = null)
{
$this->setValue((string) $value);
if (! is_string($value) ){
return false;
}

$this->setValue($value);

$tokenId = $this->getTokenIdFromHash($value);
$hash = $this->getValidationToken($tokenId);
Expand Down
7 changes: 6 additions & 1 deletion test/CsrfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ public function testCanValidateHasheWithoutId()
$this->assertTrue($this->validator->isValid($bareToken));
}

public function testCanRejectArrayValues()
{
$this->assertFalse($this->validator->isValid([]));
}

public function fakeValuesDataProvider()
{
return [
Expand All @@ -277,7 +282,7 @@ public function fakeValuesDataProvider()
['fakeTokenId'],
[md5(uniqid()) . '-'],
[md5(uniqid()) . '-' . md5(uniqid())],
['-' . md5(uniqid())]
['-' . md5(uniqid())],
];
}

Expand Down

0 comments on commit c1bed80

Please sign in to comment.