File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -1678,19 +1678,20 @@ static int php_cli_server_client_read_request_on_fragment(php_http_parser *parse
1678
1678
1679
1679
static void php_cli_server_client_save_header (php_cli_server_client * client )
1680
1680
{
1681
- zval * entry ;
1682
1681
/* Wrap header value in a zval to add is to the HashTable which acts as an array */
1683
1682
zval tmp ;
1684
1683
/* strip off the colon */
1685
1684
zend_string * lc_header_name = zend_string_tolower_ex (client -> current_header_name , /* persistent */ true);
1686
1685
GC_MAKE_PERSISTENT_LOCAL (lc_header_name );
1687
1686
1687
+ zval * entry = zend_hash_find (& client -> request .headers , lc_header_name );
1688
+ bool is_forwarded_header = strstr (ZSTR_VAL (lc_header_name ), "forwarded" );
1689
+
1688
1690
/**
1689
1691
* **Forwarded** HTTP family headers can have 1 or more values separated by a comma while still
1690
1692
* possibly be set separately by the client.
1691
1693
**/
1692
- if (!strstr (ZSTR_VAL (lc_header_name ), "forwarded" ) ||
1693
- (entry = zend_hash_find (& client -> request .headers , lc_header_name )) == NULL ) {
1694
+ if ((entry == NULL && is_forwarded_header ) || !is_forwarded_header ) {
1694
1695
ZVAL_STR (& tmp , client -> current_header_value );
1695
1696
1696
1697
/* Add the wrapped zend_string to the HashTable */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug GH-16137 duplicate *Forwarded* HTTP headers values.
3
+ --INI--
4
+ allow_url_fopen=1
5
+ --SKIPIF--
6
+ <?php
7
+ include "skipif.inc " ;
8
+ ?>
9
+ --FILE--
10
+ <?php
11
+ include "php_cli_server.inc " ;
12
+ php_cli_server_start ("echo \$_SERVER['HTTP_X_FORWARDED_FOR']; " );
13
+ $ ctx = stream_context_create (array ('http ' => array (
14
+ 'method ' => 'POST ' ,
15
+ 'header ' => array ('x-forwarded-for: 127.0.0.1 ' , 'x-forwarded-for: 192.168.1.254 ' )
16
+ )));
17
+ var_dump (file_get_contents ("http:// " . PHP_CLI_SERVER_ADDRESS , true , $ ctx ));
18
+ ?>
19
+ --EXPECT--
20
+ string(23) "127.0.0.1,192.168.1.254"
You can’t perform that action at this time.
0 commit comments