Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ ➡️➡️➡️ Laravel 9 issues: Read this before making an issue ⬅️⬅️⬅️ #152

Open
fideloper opened this issue Feb 9, 2022 · 17 comments

Comments

@fideloper
Copy link
Owner

Laravel 9 has incorporated this package into the core of Laravel.

See the upgrade guide here: https://laravel.com/docs/9.x/upgrade, search for Trusted Proxies

image

@fideloper fideloper changed the title Laravel 9 issues: Read this before making an issue ⚠️ ➡️➡️➡️ Laravel 9 issues: Read this before making an issue ⬅️⬅️⬅️ Feb 9, 2022
@Frank-Landry
Copy link

Thank you for this update. Very informative.

@svpernova09
Copy link

Cheers, should have moved this higher up in the Upgrade :D

@HDVinnie
Copy link

Hey @fideloper thanks for the update. While no longer directly related to your package maybe since you have knowledge of this middleware you can help.

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\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_FOR |
        Request::HEADER_X_FORWARDED_HOST |
        Request::HEADER_X_FORWARDED_PORT |
        Request::HEADER_X_FORWARDED_PROTO |
        Request::HEADER_X_FORWARDED_AWS_ELB;
}

Now on Laravel 9 my site has issues with Cloudflare. Yet was perfectly fine on Laravel 8 with your middleware using the Request::HEADER_X_FORWARDED_ALL

Any ideas?

@fideloper
Copy link
Owner Author

@HDVinnie I'm not really sure! What I would suggest doing is creating a test route that dumps out $_SERVER so you can see exactly what PHP is seeing when run behind CloudFlare. The HTTP_XXX values in that global array will correspond to the HTTP headers that PHP sees, which can help determine if an unknown/different header is being used.

@HDVinnie
Copy link

  "HTTP_CF_VISITOR" => "{"scheme":"https"}"
  "HTTP_X_FORWARDED_PROTO" => "https"
  "HTTP_CF_RAY" => "6dc02fb14ce11879-EWR"
  "HTTP_X_FORWARDED_FOR" => "2601:89:c701:b170:a1cf:2935:de76:e192"
  "HTTP_CF_IPCOUNTRY" => "US"
  "HTTP_ACCEPT_ENCODING" => "gzip"
  "HTTP_CF_CONNECTING_IP" => "2601:89:c701:b170:a1cf:2935:de76:e192"
  "HTTP_CDN_LOOP" => "cloudflare"
  "HTTP_HOST" => "demo.org"

Thanks for the tip....ill have to research some more.

@fideloper
Copy link
Owner Author

@HDVinnie the hostname demo.org seems suspect, right? I'm also not entirely sure how IPv6 is handled vs ipv4.

What IP do you see under REMOTE_ADDR ?

https://github.com/laravel/framework/blob/63ca843643e86fb69efc901051ae079c89a7fd09/src/Illuminate/Http/Middleware/TrustProxies.php#L85

@rafaelqm
Copy link

Thanks, it helped a lot.

@Sladewill
Copy link

@fideloper the config has been updated on the master but not been tagged yet, can this be done as that it still referencing Illuminate\Http\Request::HEADER_X_FORWARDED_ALL.

@fideloper
Copy link
Owner Author

@Sladewill I'm not sure what you mean! In Laravel 9, this project has been pulled into the core of Laravel. This package therefore isn't needed. Am I missing what you mean?

@Sladewill
Copy link

If your using this package with any other symfony or laravel components, without using Laravels core then you may still need to use this package.

For us specifically we have a common package which includes this as we have lots of customer projects ranging from laravel 5-9 which cannot be updated, which caused some issues as this automatically gets activated within Laravel 9.

@mattsims
Copy link

As per @Sladewill's request, please tag a new release that supports using this package independently with Laravel v9 🙏

@fideloper
Copy link
Owner Author

fideloper commented Jul 12, 2022

I don't have time to maintain this anymore, so while I can tag this for you, you can also just implement it yourself. It's almost literally just adding a middleware that runs:

// Trust all:
$request->setTrustedProxies(
    [$request->server->get('REMOTE_ADDR')], 
    Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_PREFIX | Request::HEADER_X_FORWARDED_AWS_ELB);

// Trust specific proxies
$request->setTrustedProxies(
    ['191.168.1.2'], 
    Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_PREFIX | Request::HEADER_X_FORWARDED_AWS_ELB);

@fideloper
Copy link
Owner Author

As per @Sladewill's request, please tag a new release that supports using this package independently with Laravel v9

I actually don't understand how I could accomplish this. I'd have to remove dependencies on something here?

image

I think you'd be better off forking this or making your own implementation. It's a super small bit of functionality.

Basically: I don't have time, but PR's welcome. (Sorry, that's not a great answer but it's all I have time for right now!)

@fideloper fideloper reopened this Jul 12, 2022
@fideloper
Copy link
Owner Author

Made another release: https://github.com/fideloper/TrustedProxy/releases/tag/4.4.2

Let me know if you hit issues!

@najathi
Copy link

najathi commented Nov 1, 2022

see under Trusted Proxies section
https://laravel.com/docs/9.x/upgrade

@Abdallah-SE
Copy link

thanks.

@InfaSysKey
Copy link

Thanks for the information! I'm trying to update an old Laravel and the information has been very useful for me.❤❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants