Skip to content

Request ips wrong order when using a load balancer  #115

@peppeocchi

Description

@peppeocchi

Hi, I recently upgrade one application from Laravel 5.2 to Laravel 5.7
Before the upgrade I was using this library (v3.3) with the configuration below

    'proxies' => '**',
...
    'headers' => [
        (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => null,
        Illuminate\Http\Request::HEADER_CLIENT_IP    => 'X_FORWARDED_FOR',
        Illuminate\Http\Request::HEADER_CLIENT_HOST  => null,
        Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
        Illuminate\Http\Request::HEADER_CLIENT_PORT  => 'X_FORWARDED_PORT',
    ]

After the upgrade, I added the TrustProxies middleware below

<?php

namespace App\Http\Middleware;

use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies = '**';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB;
}

The issue I am having might not be related to this, but basically after the upgrade

$request->ip() // the ec2 ip
$request->ips() // [ec2 ip, client ip]

It seems the order or the ips is inverted, I should be getting first the client ip, then any other ip.

Is this a configuration issue on my side or is there anything else I am missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions