xref: /PHP-7.4/ext/standard/tests/http/bug79265.phpt (revision d0d60503)
1--TEST--
2Bug #79265 (Improper injection of Host header when using fopen for http requests)
3--INI--
4allow_url_fopen=1
5--SKIPIF--
6<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
7--FILE--
8<?php
9require 'server.inc';
10
11$responses = array(
12    "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
13);
14
15$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
16
17$opts = array(
18  'http'=>array(
19    'method'=>"GET",
20    'header'=>"RandomHeader: localhost:8080\r\n" .
21              "Cookie: foo=bar\r\n" .
22              "Host: userspecifiedvalue\r\n"
23  )
24);
25$context = stream_context_create($opts);
26$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
27fseek($output, 0, SEEK_SET);
28echo stream_get_contents($output);
29fclose($fd);
30
31http_server_kill($pid);
32
33?>
34--EXPECT--
35GET / HTTP/1.0
36Connection: close
37RandomHeader: localhost:8080
38Cookie: foo=bar
39Host: userspecifiedvalue
40