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

Commit e126605

Browse files
committed
Merge branch 'hotfix/212'
Close #212
2 parents b327118 + 17c2dc9 commit e126605

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ All notable changes to this project will be documented in this file, in reverse
3939
missing `GpsPoint` validator entries to the `ValidatorPluginManager`, ensuring
4040
they may be retrieved from it correctly.
4141

42+
- [#212](https://github.com/zendframework/zend-validator/pull/212) updates the
43+
`CSRF` validator to automatically mark any non-string values as invalid,
44+
preventing errors such as array to string conversion.
45+
4246
## 2.10.1 - 2017-08-22
4347

4448
### Added

src/Csrf.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ public function __construct($options = [])
116116
*/
117117
public function isValid($value, $context = null)
118118
{
119-
$this->setValue((string) $value);
119+
if (! is_string($value)) {
120+
return false;
121+
}
122+
123+
$this->setValue($value);
120124

121125
$tokenId = $this->getTokenIdFromHash($value);
122126
$hash = $this->getValidationToken($tokenId);

test/CsrfTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ public function testCanValidateHasheWithoutId()
267267
$this->assertTrue($this->validator->isValid($bareToken));
268268
}
269269

270+
public function testCanRejectArrayValues()
271+
{
272+
$this->assertFalse($this->validator->isValid([]));
273+
}
274+
270275
public function fakeValuesDataProvider()
271276
{
272277
return [
@@ -277,7 +282,7 @@ public function fakeValuesDataProvider()
277282
['fakeTokenId'],
278283
[md5(uniqid()) . '-'],
279284
[md5(uniqid()) . '-' . md5(uniqid())],
280-
['-' . md5(uniqid())]
285+
['-' . md5(uniqid())],
281286
];
282287
}
283288

0 commit comments

Comments
 (0)