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

Throw exception when header is invalid #187

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ protected function lazyLoadHeader($index, $isGeneric = false)
try {
$headers = $class::fromString($current['line']);
} catch (Exception\InvalidArgumentException $exception) {
if ($isGeneric) {
throw $exception;
}

return $this->lazyLoadHeader($index, true);
}
if (is_array($headers)) {
Expand Down
10 changes: 10 additions & 0 deletions test/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,14 @@ public function testCRLFAttack()
$this->expectException(RuntimeException::class);
Headers::fromString("Fake: foo-bar\r\n\r\nevilContent");
}

public function testThrowExceptionOnInvalidHeader()
{
$headers = new Headers();
$headers->addHeaderLine('Location', "/mail\r\ntest");

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid header value detected');
$headers->get('Location');
}
}