Skip to content

Commit 57b259e

Browse files
authored
Merge pull request from GHSA-w3w9-vrf5-8mx8
Do not decode cookie names anymore
2 parents 00e481e + 663c9a3 commit 57b259e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ get all cookies sent with the current request.
13041304

13051305
```php
13061306
$http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) {
1307-
$key = 'react\php';
1307+
$key = 'greeting';
13081308

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

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

examples/55-server-cookie-handling.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require __DIR__ . '/../vendor/autoload.php';
44

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

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

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

2121
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');

src/Message/ServerRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function parseCookie($cookie)
186186
$nameValuePair = \explode('=', $pair, 2);
187187

188188
if (\count($nameValuePair) === 2) {
189-
$key = \urldecode($nameValuePair[0]);
189+
$key = $nameValuePair[0];
190190
$value = \urldecode($nameValuePair[1]);
191191
$result[$key] = $value;
192192
}

tests/Message/ServerRequestTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function testUrlEncodingForKeyWillReturnValidArray()
251251
);
252252

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

257257
public function testCookieWithoutSpaceAfterSeparatorWillBeAccepted()

0 commit comments

Comments
 (0)