File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -730,6 +730,23 @@ class ConfigInfo {
730
730
public $ websocket_url = false ;
731
731
public $ websocket_proxyport = false ;
732
732
733
+ /**
734
+ * If the web server is NOT behind a reverse proxy, you may optionally wish
735
+ * to ignore forwarded IP headers such as x-forwarded-for and variations by
736
+ * setting this to false. This will help to preserve authenticity of IPs by
737
+ * only trusting IP addresses directly seen by the server.
738
+ *
739
+ * Never set this to false if you ARE behind a reverse proxy, otherwise all
740
+ * requests will appear to originate from the same IP address (the proxy).
741
+ *
742
+ * If behind a reverse proxy, set to `true`:
743
+ * $CFG->trust_forwarded_ip = true; // (default)
744
+ *
745
+ * If not using a reverse proxy, set to `false`:
746
+ * $CFG->trust_forwarded_ip = false;
747
+ */
748
+ public $ trust_forwarded_ip = true ;
749
+
733
750
/*
734
751
* This is the internal version of the datbase. This is an internal
735
752
* value and set in setup.php and read in migrate.php - you should not
Original file line number Diff line number Diff line change @@ -476,6 +476,8 @@ public static function send400($msg='Malformed request', $detail=null) {
476
476
*/
477
477
public static function getIP () {
478
478
479
+ global $ CFG ;
480
+
479
481
//Just get the headers if we can or else use the SERVER global
480
482
if ( function_exists ( 'apache_request_headers ' ) ) {
481
483
$ rawheaders = apache_request_headers ();
@@ -497,6 +499,11 @@ public static function getIP() {
497
499
498
500
$ the_ip = false ;
499
501
502
+ // When not behind proxy, trust IP from web server over headers
503
+ if ( $ CFG ->trust_forwarded_ip === false && array_key_exists ( 'REMOTE_ADDR ' , $ _SERVER ) ) {
504
+ $ the_ip = filter_var ( $ _SERVER ['REMOTE_ADDR ' ], FILTER_VALIDATE_IP , $ filter_option );
505
+ }
506
+
500
507
// Check Cloudflare headers
501
508
if ( $ the_ip === false && array_key_exists ( 'http_cf_connecting_ip ' , $ headers ) ) {
502
509
$ pieces = explode (', ' ,$ headers ['http_cf_connecting_ip ' ]);
You can’t perform that action at this time.
0 commit comments