Problem/Motivation
Currently the below code displays the ip address as 127.0.0.1.
$this->logger('user')->notice('Login attempt failed from %ip.', ['%ip' => $this->getRequest()->getClientIp()]);
How to find the exact ip address, tried out to get the ip address from the $_SERVER which provides the ip address as 127.0.0.1
Steps to reproduce
When tried to login from user/login with invalid credentials, then on recent logs able to see the below message.
Login attempt failed from 127.0.0.1.
Proposed resolution
Need to get the exact ip address like the value we get from https://whatismyipaddress.com/
Comments
Comment #2
cilefen commentedIs there a load balancer or forward cache? What is the PHP and web server integration? You have probably missed a setup step documented in the default settings.php.
This is not a bug.
Comment #3
sarikak commented@cilefen I configured new drupal 10 set up in localhost in xampp.
There is no load balancer or forward cache.
Please find the details:
Drupal version : 10.3.5
DB driver : mysql
DB hostname : localhost
DB port : 3306
DB username : root
DB name : d10
Database : Connected
Drupal bootstrap : Successful
Default theme : olivero
Admin theme : claro
PHP binary : C:/xampp/php/php.exe
PHP config : C:/xampp/php/php.ini
PHP OS : WINNT
PHP version : 8.1.6
Drush script : C:/xampp/htdocs/d10/vendor/drush/drush/drush
Drush version : 12.5.3.0
Drush temp : C:/Users/admin/AppData/Local/Temp
Drush configs : C:/xampp/htdocs/d10/vendor/drush/drush/drush.yml
Install profile : standard
Drupal root : C:/xampp/htdocs/d10/web
Site path : sites/default
Files, Public : sites/default/files
Files, Temp : C:\xampp\tmp
The settings.php code:
Comment #4
sarikak commentedThe PHP code snippet to get the current user's IP address also provides the value of 127.0.0.1
Added the below code in hook_form_alter function of user_login_form.
Tried with Login Event subscriber as well, but could not find any solution.
The below code from the Drupal core module, UserLoginForm.phpalso unaable to give the exact ip address but shows the 127.0.0.1.
@cilefen Can you please suggest a way to get the ip address.
Appreciate any inputs.
Thanks
Comment #5
cilefen commentedIf this is local development your IP address is 127.0.0.1 and this working as expected. Which IP address were you expecting?
My advice is to use DDEV instead of XAMPP.
Comment #6
mdsohaib4242 commentedYou can check the
$_SERVERheaders to see if the real IP address is passed via headers likeX-Forwarded-FororHTTP_X_FORWARDED_FOR.At last check for the
REMOTE_ADDRif no valid IP was foundComment #7
sarikak commentedI want this ip address rather than 127.0.0.1
ifconfig.co — What is my IP address?
165.225.***.***
This issue is raised from one of our client security team. Please find below are the issue details:
IP address-based blocking bypass via XForwarded-For
The vulnerability involves improper IP address handling in Drupal's brute force protection mechanism, leading to an IP address-based blocking bypass. This misconfiguration occurs because the X-Forwarded-For header is not correctly processed, allowing attackers to evade brute force protections.
Properly configure IP detection so that the real IP address is correctly parsed and used by the brute force protection mechanism
Note:- Currently this issue we are checking on local , once issue fixed we will check on the server.
We have checked with the $_server variable also we are getting same 127.0.0.1.
Is there anything we need to enable in server/apache level?
Comment #8
cilefen commentedDrupal is ready to be set up properly to parse forwarded-for headers. At this stage you may wish to consult XAMPP support or with a systems administrator to debug your specific setup.
Again, this is not a bug in Drupal.
Comment #9
quietone commented@sarikak, The Drupal Core issue queue is not the ideal place for support requests. The 'support request' option is there for filing support issues for contributed modules and themes. There are several support options listed on our support page (Community > Support at the top of Drupal.org) and there is Drupal Slack. You may get better replies in one of those places.
Comment #10
quietone commentedClosing this based on #8