From 9af5995fab77f51230281cf7dd96b9eac98214c2 Mon Sep 17 00:00:00 2001 From: ppodds Date: Sun, 12 Dec 2021 17:39:49 +0800 Subject: [PATCH 1/3] support x-forwarded-prefix --- src/Illuminate/Http/Middleware/TrustProxies.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Http/Middleware/TrustProxies.php b/src/Illuminate/Http/Middleware/TrustProxies.php index e9e06968b806..c5a5c05e487e 100644 --- a/src/Illuminate/Http/Middleware/TrustProxies.php +++ b/src/Illuminate/Http/Middleware/TrustProxies.php @@ -19,7 +19,7 @@ class TrustProxies * * @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; + 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_PREFIX | Request::HEADER_X_FORWARDED_AWS_ELB; /** * Handle an incoming request. @@ -116,9 +116,13 @@ protected function getTrustedHeaderNames() case 'HEADER_X_FORWARDED_PROTO': case Request::HEADER_X_FORWARDED_PROTO: return Request::HEADER_X_FORWARDED_PROTO; + + case 'HEADER_X_FORWARDED_PREFIX': + case Request::HEADER_X_FORWARDED_PREFIX: + return Request::HEADER_X_FORWARDED_PREFIX; default: - return 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; + return 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; } return $this->headers; From 31e786a4a3357b3d7f4ad3a0d1f7e79239e69e3f Mon Sep 17 00:00:00 2001 From: ppodds Date: Mon, 13 Dec 2021 02:05:59 +0800 Subject: [PATCH 2/3] fix TrustProxies code style --- src/Illuminate/Http/Middleware/TrustProxies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Middleware/TrustProxies.php b/src/Illuminate/Http/Middleware/TrustProxies.php index c5a5c05e487e..1159e5072307 100644 --- a/src/Illuminate/Http/Middleware/TrustProxies.php +++ b/src/Illuminate/Http/Middleware/TrustProxies.php @@ -116,7 +116,7 @@ protected function getTrustedHeaderNames() case 'HEADER_X_FORWARDED_PROTO': case Request::HEADER_X_FORWARDED_PROTO: return Request::HEADER_X_FORWARDED_PROTO; - + case 'HEADER_X_FORWARDED_PREFIX': case Request::HEADER_X_FORWARDED_PREFIX: return Request::HEADER_X_FORWARDED_PREFIX; From d7c5e25fa4d8e3f2528b436680b3cf946837e520 Mon Sep 17 00:00:00 2001 From: ppodds Date: Mon, 13 Dec 2021 02:24:33 +0800 Subject: [PATCH 3/3] test x-forwarded-prefix in TrustProxiesTest --- tests/Http/Middleware/TrustProxiesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Http/Middleware/TrustProxiesTest.php b/tests/Http/Middleware/TrustProxiesTest.php index 6f653d09874d..1fbf245e205a 100644 --- a/tests/Http/Middleware/TrustProxiesTest.php +++ b/tests/Http/Middleware/TrustProxiesTest.php @@ -13,7 +13,7 @@ class TrustProxiesTest extends TestCase * * @var int */ - protected $headerAll = 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; + protected $headerAll = 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; /** * Test that Symfony does indeed NOT trust X-Forwarded-*