Skip to content

Commit

Permalink
Don't treat any WS as start of header
Browse files Browse the repository at this point in the history
Check that the header occurs after \n, not other whitespace
characters.
  • Loading branch information
nikic committed Feb 24, 2020
1 parent 3d9c023 commit 56cdbe6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
static zend_bool check_has_header(const char *headers, const char *header) {
const char *s = headers;
while ((s = strstr(s, header))) {
if (s == headers || *(s-1) == '\r' || *(s-1) == '\n' || *(s-1) == '\t' || *(s-1) == ' ') {
if (s == headers || *(s-1) == '\n') {
return 1;
}
s++;
Expand Down Expand Up @@ -495,8 +495,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,

/* remove Proxy-Authorization header */
if (use_proxy && use_ssl && (s = strstr(t, "proxy-authorization:")) &&
(s == t || *(s-1) == '\r' || *(s-1) == '\n' ||
*(s-1) == '\t' || *(s-1) == ' ')) {
(s == t || *(s-1) == '\n')) {
char *p = s + sizeof("proxy-authorization:") - 1;

while (s > t && (*(s-1) == ' ' || *(s-1) == '\t')) s--;
Expand Down
38 changes: 38 additions & 0 deletions ext/standard/tests/http/bug79265_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Bug #79265 variation: "host:" not at start of header
--INI--
allow_url_fopen=1
--SKIPIF--
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
--FILE--
<?php
require 'server.inc';

$responses = array(
"data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
);

$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);

$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"RandomHeader: host:8080\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
fseek($output, 0, SEEK_SET);
echo stream_get_contents($output);
fclose($fd);

http_server_kill($pid);

?>
--EXPECT--
GET / HTTP/1.0
Host: 127.0.0.1:12342
Connection: close
RandomHeader: host:8080
Cookie: foo=bar

0 comments on commit 56cdbe6

Please sign in to comment.