Skip to content

Commit

Permalink
Merge pull request from GHSA-w3w9-vrf5-8mx8
Browse files Browse the repository at this point in the history
Do not decode cookie names anymore
  • Loading branch information
clue committed Aug 23, 2022
2 parents 00e481e + 663c9a3 commit 57b259e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -1304,7 +1304,7 @@ get all cookies sent with the current request.

```php
$http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) {
$key = 'react\php';
$key = 'greeting';

if (isset($request->getCookieParams()[$key])) {
$body = "Your cookie value is: " . $request->getCookieParams()[$key] . "\n";
Expand All @@ -1316,7 +1316,7 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf

return React\Http\Message\Response::plaintext(
"Your cookie has been set.\n"
)->withHeader('Set-Cookie', urlencode($key) . '=' . urlencode('test;more'));
)->withHeader('Set-Cookie', $key . '=' . urlencode('Hello world!'));
});
```

Expand Down
4 changes: 2 additions & 2 deletions examples/55-server-cookie-handling.php
Expand Up @@ -3,7 +3,7 @@
require __DIR__ . '/../vendor/autoload.php';

$http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) {
$key = 'react\php';
$key = 'greeting';

if (isset($request->getCookieParams()[$key])) {
$body = "Your cookie value is: " . $request->getCookieParams()[$key] . "\n";
Expand All @@ -15,7 +15,7 @@

return React\Http\Message\Response::plaintext(
"Your cookie has been set.\n"
)->withHeader('Set-Cookie', urlencode($key) . '=' . urlencode('test;more'));
)->withHeader('Set-Cookie', $key . '=' . urlencode('Hello world!'));
});

$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
Expand Down
2 changes: 1 addition & 1 deletion src/Message/ServerRequest.php
Expand Up @@ -186,7 +186,7 @@ private function parseCookie($cookie)
$nameValuePair = \explode('=', $pair, 2);

if (\count($nameValuePair) === 2) {
$key = \urldecode($nameValuePair[0]);
$key = $nameValuePair[0];
$value = \urldecode($nameValuePair[1]);
$result[$key] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/ServerRequestTest.php
Expand Up @@ -251,7 +251,7 @@ public function testUrlEncodingForKeyWillReturnValidArray()
);

$cookies = $this->request->getCookieParams();
$this->assertEquals(array('react;php' => 'is great'), $cookies);
$this->assertEquals(array('react%3Bphp' => 'is great'), $cookies);
}

public function testCookieWithoutSpaceAfterSeparatorWillBeAccepted()
Expand Down

0 comments on commit 57b259e

Please sign in to comment.