Closed
Description
Symfony version(s) affected: 4.1.3
Description
I have a problem about 500 error after I deployed a Symfony Application to Elastic Beanstalk.
Could you please give me an advice?
How to reproduce
Possible Solution
Additional context
[root@ip-xxx-xxx-xxx-xxx public]# vim index.php
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::HEADER_X_FORWARDED_AWS_ELB;
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts(array('^(.+\.)?XXXX\.XXX$'));
}
[root@ip-xxx-xxx-xxx-xxx public]# php index.php
Notice: Uninitialized string offset: 0 in /var/app/current/vendor/symfony/http-foundation/Request.php on line 1988
Notice: Uninitialized string offset: 0 in /var/app/current/vendor/symfony/http-foundation/Request.php on line 1988
Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /var/app/current/vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php on line 52
Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /var/app/current/vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php on line 53
private function normalizeAndFilterClientIps(array $clientIps, $ip)
{
if (!$clientIps) {
return array();
}
$clientIps[] = $ip; // Complete the IP chain with the IP the request actually came from
$firstTrustedIp = null;
foreach ($clientIps as $key => $clientIp) {
if (strpos($clientIp, '.')) {
// Strip :port from IPv4 addresses. This is allowed in Forwarded
// and may occur in X-Forwarded-For.
$i = strpos($clientIp, ':');
if ($i) {
$clientIps[$key] = $clientIp = substr($clientIp, 0, $i);
}
// line 1988 ---->
} elseif ('[' == $clientIp[0]) {
// Strip brackets and :port from IPv6 addresses.
$i = strpos($clientIp, ']', 1);
$clientIps[$key] = $clientIp = substr($clientIp, 1, $i - 1);
}
if (!filter_var($clientIp, FILTER_VALIDATE_IP)) {
unset($clientIps[$key]);
continue;
}
if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
unset($clientIps[$key]);
// Fallback to this when the client IP falls into the range of trusted proxies
if (null === $firstTrustedIp) {
$firstTrustedIp = $clientIp;
}
}
}
// Now the IP chain contains only untrusted proxies and the client IP
return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp);
}