You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* The other headers are non-standard, but widely used
72
82
* by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
83
+
*
84
+
* @deprecated since version 3.3, to be removed in 4.0
73
85
*/
74
86
protectedstatic$trustedHeaders = array(
75
87
self::HEADER_FORWARDED => 'FORWARDED',
@@ -210,6 +222,17 @@ class Request
210
222
private$isHostValid = true;
211
223
private$isClientIpsValid = true;
212
224
225
+
privatestatic$trustedHeaderSet = -1;
226
+
227
+
/** @deprecated since version 3.3, to be removed in 4.0 */
228
+
privatestatic$trustedHeaderNames = array(
229
+
self::HEADER_FORWARDED => 'FORWARDED',
230
+
self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
231
+
self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
232
+
self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
233
+
self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
234
+
);
235
+
213
236
/**
214
237
* Constructor.
215
238
*
@@ -548,11 +571,26 @@ public function overrideGlobals()
548
571
*
549
572
* You should only list the reverse proxies that you manage directly.
550
573
*
551
-
* @param array $proxies A list of trusted proxies
574
+
* @param array $proxies A list of trusted proxies
575
+
* @param int $trustedHeaderSet A bit field of Request::HEADER_*, usually either Request::HEADER_FORWARDED or Request::HEADER_X_FORWARDED_ALL, to set which headers to trust from your proxies
576
+
*
577
+
* @throws \InvalidArgumentException When $trustedHeaderSet is invalid
publicstaticfunctionsetTrustedProxies(array$proxies/*, int $trustedHeaderSet*/)
554
580
{
555
581
self::$trustedProxies = $proxies;
582
+
583
+
if (2 > func_num_args()) {
584
+
@trigger_error(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument. Not defining it is deprecated since version 3.3 and will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
@@ -565,6 +603,16 @@ public static function getTrustedProxies()
565
603
returnself::$trustedProxies;
566
604
}
567
605
606
+
/**
607
+
* Gets the set of trusted headers from trusted proxies.
608
+
*
609
+
* @return int A bit field of Request::HEADER_* that defines which headers are trusted from your proxies
610
+
*/
611
+
publicstaticfunctiongetTrustedHeaderSet()
612
+
{
613
+
returnself::$trustedHeaderSet;
614
+
}
615
+
568
616
/**
569
617
* Sets a list of trusted host patterns.
570
618
*
@@ -608,14 +656,22 @@ public static function getTrustedHosts()
608
656
* @param string $value The header name
609
657
*
610
658
* @throws \InvalidArgumentException
659
+
*
660
+
* @deprecated since version 3.3, to be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.', __METHOD__), E_USER_DEPRECATED);
665
+
614
666
if (!array_key_exists($key, self::$trustedHeaders)) {
615
667
thrownew \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
616
668
}
617
669
618
670
self::$trustedHeaders[$key] = $value;
671
+
672
+
if (null !== $value) {
673
+
self::$trustedHeaderNames[$key] = $value;
674
+
}
619
675
}
620
676
621
677
/**
@@ -626,9 +682,15 @@ public static function setTrustedHeaderName($key, $value)
626
682
* @return string The header name
627
683
*
628
684
* @throws \InvalidArgumentException
685
+
*
686
+
* @deprecated since version 3.3, to be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.
629
687
*/
630
688
publicstaticfunctiongetTrustedHeaderName($key)
631
689
{
690
+
if (2 > func_num_args() || func_get_arg(1)) {
691
+
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.', __METHOD__), E_USER_DEPRECATED);
692
+
}
693
+
632
694
if (!array_key_exists($key, self::$trustedHeaders)) {
633
695
thrownew \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
0 commit comments