Skip to content
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
13 changes: 8 additions & 5 deletions src/Io/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public function __construct(
\parse_str($query, $this->queryParams);
}

$this->cookies = $this->parseCookie($this->getHeaderLine('Cookie'));
// Multiple cookie headers are not allowed according
// to https://tools.ietf.org/html/rfc6265#section-5.4
$cookieHeaders = $this->getHeader("Cookie");

if (count($cookieHeaders) === 1) {
$this->cookies = $this->parseCookie($cookieHeaders[0]);
}
}

public function getServerParams()
Expand Down Expand Up @@ -146,10 +152,7 @@ public function withoutAttribute($name)
*/
private function parseCookie($cookie)
{
// PSR-7 `getHeaderLine('Cookie')` will return multiple
// cookie header comma-seperated. Multiple cookie headers
// are not allowed according to https://tools.ietf.org/html/rfc6265#section-5.4
if ($cookie === '' || \strpos($cookie, ',') !== false) {
if ($cookie === '') {
return array();
}

Expand Down
19 changes: 19 additions & 0 deletions tests/StreamingServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,25 @@ public function testRequestCookieWithSeparatorWillBeAddedToServerRequest()
$this->assertEquals(array('hello' => 'world', 'test' => 'abc'), $requestValidation->getCookieParams());
}

public function testRequestCookieWithCommaValueWillBeAddedToServerRequest() {
$requestValidation = null;
$server = new StreamingServer(function (ServerRequestInterface $request) use (&$requestValidation) {
$requestValidation = $request;
});

$server->listen($this->socket);
$this->socket->emit('connection', array($this->connection));

$data = "GET / HTTP/1.1\r\n";
$data .= "Host: example.com:80\r\n";
$data .= "Connection: close\r\n";
$data .= "Cookie: test=abc,def; hello=world\r\n";
$data .= "\r\n";

$this->connection->emit('data', array($data));
$this->assertEquals(array('test' => 'abc,def', 'hello' => 'world'), $requestValidation->getCookieParams());
}

private function createGetRequest()
{
$data = "GET / HTTP/1.1\r\n";
Expand Down