1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
--TEST--
GHSA-hgf5-96fm-v528: Header parser of http stream wrapper does not handle folded headers (correct middle pos)
--FILE--
<?php
$serverCode = <<<'CODE'
$ctxt = stream_context_create([
"socket" => [
"tcp_nodelay" => true
]
]);
$server = stream_socket_server(
"tcp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $ctxt);
phpt_notify_server_start($server);
$conn = stream_socket_accept($server);
phpt_notify(message:"server-accepted");
$result = fread($conn, 1024);
$encoded_result = base64_encode($result);
fwrite($conn, "HTTP/1.0 200 Ok\r\nContent-Type: text/html; charset=utf-8\r\n\r\n$encoded_result\r\n");
CODE;
$clientCode = <<<'CODE'
$opts = [
"http" => [
"method" => "GET",
"header" => "Cookie: x=y\r\nAuthorization: Bearer x\r\n"
]
];
$ctx = stream_context_create($opts);
var_dump(explode("\r\n", base64_decode(file_get_contents("http://user:pwd@{{ ADDR }}", false, $ctx))));
var_dump($http_response_header);
CODE;
include sprintf("%s/../../../openssl/tests/ServerClientTestCase.inc", __DIR__);
ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
?>
--EXPECTF--
array(7) {
[0]=>
string(14) "GET / HTTP/1.1"
[1]=>
string(%d) "Host: 127.0.0.1:%d"
[2]=>
string(17) "Connection: close"
[3]=>
string(11) "Cookie: x=y"
[4]=>
string(23) "Authorization: Bearer x"
[5]=>
string(0) ""
[6]=>
string(0) ""
}
array(2) {
[0]=>
string(15) "HTTP/1.0 200 Ok"
[1]=>
string(38) "Content-Type: text/html; charset=utf-8"
}
|