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

Commit 4a2ebce

Browse files
committed
Merge branch 'hotfix/187' into develop
Forward port #187
2 parents d4e4dc4 + 06fda14 commit 4a2ebce

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ All notable changes to this project will be documented in this file, in reverse
4646

4747
- [#184](https://github.com/zendframework/zend-http/pull/184) fixes responses for request through the proxy with `HTTP/1.1 200 Connection established` header.
4848

49+
- [#187](https://github.com/zendframework/zend-http/pull/187) fixes infinite recursion on invalid header. Now `InvalidArgumentException` exception is thrown.
50+
4951
## 2.10.0 - 2019-02-19
5052

5153
### Added

src/Headers.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public function forceLoading()
455455

456456
/**
457457
* @param $index
458-
* @param bool $isGeneric
458+
* @param bool $isGeneric If true, there is no need to parse $index and call the ClassLoader.
459459
* @return mixed|void
460460
*/
461461
protected function lazyLoadHeader($index, $isGeneric = false)
@@ -472,6 +472,12 @@ protected function lazyLoadHeader($index, $isGeneric = false)
472472
try {
473473
$headers = $class::fromString($current['line']);
474474
} catch (Exception\InvalidArgumentException $exception) {
475+
// Generic Header should throw an exception if it fails
476+
if ($isGeneric) {
477+
throw $exception;
478+
}
479+
480+
// Retry one more time with GenericHeader
475481
return $this->lazyLoadHeader($index, true);
476482
}
477483
if (is_array($headers)) {

test/HeadersTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,14 @@ public function testCRLFAttack()
315315
$this->expectException(RuntimeException::class);
316316
Headers::fromString("Fake: foo-bar\r\n\r\nevilContent");
317317
}
318+
319+
public function testThrowExceptionOnInvalidHeader()
320+
{
321+
$headers = new Headers();
322+
$headers->addHeaderLine('Location', "/mail\r\ntest");
323+
324+
$this->expectException(InvalidArgumentException::class);
325+
$this->expectExceptionMessage('Invalid header value detected');
326+
$headers->get('Location');
327+
}
318328
}

0 commit comments

Comments
 (0)