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

Commit ad57a6f

Browse files
committed
Throw exception when header is invalid
Fixes #180 - infinite recursion
1 parent e56f731 commit ad57a6f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Headers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ protected function lazyLoadHeader($index, $isGeneric = false)
472472
try {
473473
$headers = $class::fromString($current['line']);
474474
} catch (Exception\InvalidArgumentException $exception) {
475+
if ($isGeneric) {
476+
throw $exception;
477+
}
478+
475479
return $this->lazyLoadHeader($index, true);
476480
}
477481
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)