Skip to content

Commit

Permalink
Fixes yiisoft#16006: Handle case when X-Forwarded-Host header have …
Browse files Browse the repository at this point in the history
…multiple hosts separated with a comma
  • Loading branch information
pgaultier authored and samdark committed Mar 31, 2018
1 parent bd837bc commit 35ac718
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------

- Bug #16006: Handle case when `X-Forwarded-Host` header have multiple hosts separated with a comma (pgaultier)
- Bug #16010: Fixed `yii\filters\ContentNegotiator` behavior when GET parameters contain an array (rugabarbo)
- Bug #14660: Fixed `yii\caching\DbCache` concurrency issue when set values with the same key (rugabarbo)
- Bug #15988: Fixed bash completion (alekciy)
Expand Down
2 changes: 1 addition & 1 deletion framework/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ public function getHostInfo()
$http = $secure ? 'https' : 'http';

if ($this->headers->has('X-Forwarded-Host')) {
$this->_hostInfo = $http . '://' . $this->headers->get('X-Forwarded-Host');
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Forwarded-Host'))[0]);
} elseif ($this->headers->has('Host')) {
$this->_hostInfo = $http . '://' . $this->headers->get('Host');
} elseif (isset($_SERVER['SERVER_NAME'])) {
Expand Down
13 changes: 13 additions & 0 deletions tests/framework/web/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ public function getHostInfoDataProvider()
'example3.com',
]
],
// forwarded from trusted proxy
[
[
'HTTP_X_FORWARDED_HOST' => 'example3.com, example2.com',
'HTTP_HOST' => 'example1.com',
'SERVER_NAME' => 'example2.com',
'REMOTE_ADDR' => '192.168.0.1',
],
[
'http://example3.com',
'example3.com',
]
],
];
}

Expand Down

0 comments on commit 35ac718

Please sign in to comment.