Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Process X-Forwarded-For header in correct order #3095

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Zend/Session/Validator/RemoteAddr.php
Expand Up @@ -102,7 +102,7 @@ protected function getIpAddress()
// proxy IP address
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($ips[0]);
return trim(end($ips));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Session/Validator/RemoteAddrTest.php
Expand Up @@ -106,7 +106,7 @@ public function testMultipleHttpXForwardedFor()
{
$this->backup();
$_SERVER['REMOTE_ADDR'] = '0.1.2.3';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '2.1.2.3, 1.1.2.3';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '1.1.2.3, 2.1.2.3';
RemoteAddr::setUseProxy(true);
$validator = new RemoteAddr();
RemoteAddr::setUseProxy(false);
Expand Down