How to get real IP from behind Sucuri firewallMagento2: Re-direct to custom URL from observermagento 2 : Get country from IP addressmagento 2.1: Is it possible to make the admin page url work from two seperate URLs?How to get Geo IP of customer in magento2?Exclude subfolders from geoip redirectHow can disable the cache for some block in Magento 2
Why was Germany not as successful as other Europeans in establishing overseas colonies?
Why do games have consumables?
Is there really no use for MD5 anymore?
How to get a plain text file version of a CP/M .BAS (M-BASIC) program?
How to creep the reader out with what seems like a normal person?
Is there an official tutorial for installing Ubuntu 18.04+ on a device with an SSD and an additional internal hard drive?
Who is the Umpire in this picture?
Combinable filters
How come there are so many candidates for the 2020 Democratic party presidential nomination?
French for 'It must be my imagination'?
Why is it that the natural deduction method can't test for invalidity?
Is there any limitation with Arduino Nano serial communication distance?
What's the polite way to say "I need to urinate"?
Binary Numbers Magic Trick
simple conditions equation
Error message with tabularx
What are the potential pitfalls when using metals as a currency?
Sci fi novel series with instant travel between planets through gates. A river runs through the gates
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
Examples of subgroups where it's nontrivial to show closure under multiplication?
Critique of timeline aesthetic
Is it possible to determine the symmetric encryption method used by output size?
What is the difference between `command a[bc]d` and `command `ab,cd`
What is the relationship between spectral sequences and obstruction theory?
How to get real IP from behind Sucuri firewall
Magento2: Re-direct to custom URL from observermagento 2 : Get country from IP addressmagento 2.1: Is it possible to make the admin page url work from two seperate URLs?How to get Geo IP of customer in magento2?Exclude subfolders from geoip redirectHow can disable the cache for some block in Magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a Magento store on an Ngix behind Sucuri firewall and we hide prices if the IP is outside of UK.
A bruteforce attack was bypassing the firewall so the hosting added the following rules to prevent bypass:
location /
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# Existing NGINX rules
This works fine except that all IPs are transalted as the firewall one based in UK. To get the real IP Sucuri suggested to add the following:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted Firewall IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29; # this line can be removed if IPv6 is
disabled
This second rule causes a problem. Once the IP is translated and if it is different than the allowed Sucuri IP addresses, the requests is restricted with 403 Forbidden error.
Is it impossible to have the store behind a firewall and still get the real IP. I am sure that this is not the only store in the world behind a firewall, which needs to server different content depending on the IP.
The code in Magento that gets the IP of the client is something like this:
$geoIP = Mage::getSingleton('geoip/country');
if ($geoIP->isCountryAllowed()) {....
Any alternative? SOlution? My hosting provider is useless..
geoip
add a comment |
I have a Magento store on an Ngix behind Sucuri firewall and we hide prices if the IP is outside of UK.
A bruteforce attack was bypassing the firewall so the hosting added the following rules to prevent bypass:
location /
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# Existing NGINX rules
This works fine except that all IPs are transalted as the firewall one based in UK. To get the real IP Sucuri suggested to add the following:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted Firewall IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29; # this line can be removed if IPv6 is
disabled
This second rule causes a problem. Once the IP is translated and if it is different than the allowed Sucuri IP addresses, the requests is restricted with 403 Forbidden error.
Is it impossible to have the store behind a firewall and still get the real IP. I am sure that this is not the only store in the world behind a firewall, which needs to server different content depending on the IP.
The code in Magento that gets the IP of the client is something like this:
$geoIP = Mage::getSingleton('geoip/country');
if ($geoIP->isCountryAllowed()) {....
Any alternative? SOlution? My hosting provider is useless..
geoip
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30
add a comment |
I have a Magento store on an Ngix behind Sucuri firewall and we hide prices if the IP is outside of UK.
A bruteforce attack was bypassing the firewall so the hosting added the following rules to prevent bypass:
location /
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# Existing NGINX rules
This works fine except that all IPs are transalted as the firewall one based in UK. To get the real IP Sucuri suggested to add the following:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted Firewall IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29; # this line can be removed if IPv6 is
disabled
This second rule causes a problem. Once the IP is translated and if it is different than the allowed Sucuri IP addresses, the requests is restricted with 403 Forbidden error.
Is it impossible to have the store behind a firewall and still get the real IP. I am sure that this is not the only store in the world behind a firewall, which needs to server different content depending on the IP.
The code in Magento that gets the IP of the client is something like this:
$geoIP = Mage::getSingleton('geoip/country');
if ($geoIP->isCountryAllowed()) {....
Any alternative? SOlution? My hosting provider is useless..
geoip
I have a Magento store on an Ngix behind Sucuri firewall and we hide prices if the IP is outside of UK.
A bruteforce attack was bypassing the firewall so the hosting added the following rules to prevent bypass:
location /
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# Existing NGINX rules
This works fine except that all IPs are transalted as the firewall one based in UK. To get the real IP Sucuri suggested to add the following:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted Firewall IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29; # this line can be removed if IPv6 is
disabled
This second rule causes a problem. Once the IP is translated and if it is different than the allowed Sucuri IP addresses, the requests is restricted with 403 Forbidden error.
Is it impossible to have the store behind a firewall and still get the real IP. I am sure that this is not the only store in the world behind a firewall, which needs to server different content depending on the IP.
The code in Magento that gets the IP of the client is something like this:
$geoIP = Mage::getSingleton('geoip/country');
if ($geoIP->isCountryAllowed()) {....
Any alternative? SOlution? My hosting provider is useless..
geoip
geoip
asked Mar 11 '18 at 14:14
ShakamalShakamal
388
388
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30
add a comment |
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30
add a comment |
2 Answers
2
active
oldest
votes
We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass"
location /
# Block everything that isn't sucuri
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# other nginx config
As this was below the already configured:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29;
Magento 1
So long as the code uses the core method:
Mage::helper('core/http')->getRemoteAddr()
You can add a list of headers to app/etc/local.xml
inside of config->global
node that are used to determine the "real" ip. Something like:
<remote_addr_headers>
<header1>HTTP_X_SUCURI_CLIENTIP</header1>
<header2>HTTP_X_REAL_IP</header2>
<header3>HTTP_X_FORWARDED_FOR</header3>
</remote_addr_headers>
Then you can remove the real_ip_header
and set_real_ip_from
from the nginx config. Allowing all traffic not from Sucuri to be blocked and still able to obtain the true IP within magento. You can test this with something like:
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
Mage::app('admin');
print_r($_SERVER);
echo 'address: '.Mage::helper('core/http')->getRemoteAddr();
Magento 2
This appears to a little harder, I haven't dug as deep but on initial look.
- vendor/magento/framework/Session/Validator.php
is sensitive to configuration, on if it should use: http_x_forwarded_for
or remote_addr
- vendor/magento/framework/HTTP/PhpEnvironment/Request.php:725
has the method getClientIp
which appears to use the first it finds from HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, REMOTE_ADDR
- vendor/magento/magento2-base/pub/errors/processor.php:312
had the method _getClientIp
which uses REMOTE_ADDR
and if that isn't found returns undefined
I may be wrong but I haven't spotted anywhere a single value can be configured, or a list to try. So at this point would suggest adding something like the following to app/etc/bootstrap.php
$trustedIpHeaders = [
'HTTP_X_SUCURI_CLIENTIP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
];
$headersToPopulate = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
];
foreach($trustedIpHeaders as $trustedIpHeader)
if(isset($_SERVER[$trustedIpHeader]))
foreach($headersToPopulate as $headerToPopulate)
$_SERVER[$headerToPopulate] = $_SERVER[$trustedIpHeader]
break;
add a comment |
For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php:
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']))
{
$_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f216873%2fhow-to-get-real-ip-from-behind-sucuri-firewall%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass"
location /
# Block everything that isn't sucuri
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# other nginx config
As this was below the already configured:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29;
Magento 1
So long as the code uses the core method:
Mage::helper('core/http')->getRemoteAddr()
You can add a list of headers to app/etc/local.xml
inside of config->global
node that are used to determine the "real" ip. Something like:
<remote_addr_headers>
<header1>HTTP_X_SUCURI_CLIENTIP</header1>
<header2>HTTP_X_REAL_IP</header2>
<header3>HTTP_X_FORWARDED_FOR</header3>
</remote_addr_headers>
Then you can remove the real_ip_header
and set_real_ip_from
from the nginx config. Allowing all traffic not from Sucuri to be blocked and still able to obtain the true IP within magento. You can test this with something like:
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
Mage::app('admin');
print_r($_SERVER);
echo 'address: '.Mage::helper('core/http')->getRemoteAddr();
Magento 2
This appears to a little harder, I haven't dug as deep but on initial look.
- vendor/magento/framework/Session/Validator.php
is sensitive to configuration, on if it should use: http_x_forwarded_for
or remote_addr
- vendor/magento/framework/HTTP/PhpEnvironment/Request.php:725
has the method getClientIp
which appears to use the first it finds from HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, REMOTE_ADDR
- vendor/magento/magento2-base/pub/errors/processor.php:312
had the method _getClientIp
which uses REMOTE_ADDR
and if that isn't found returns undefined
I may be wrong but I haven't spotted anywhere a single value can be configured, or a list to try. So at this point would suggest adding something like the following to app/etc/bootstrap.php
$trustedIpHeaders = [
'HTTP_X_SUCURI_CLIENTIP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
];
$headersToPopulate = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
];
foreach($trustedIpHeaders as $trustedIpHeader)
if(isset($_SERVER[$trustedIpHeader]))
foreach($headersToPopulate as $headerToPopulate)
$_SERVER[$headerToPopulate] = $_SERVER[$trustedIpHeader]
break;
add a comment |
We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass"
location /
# Block everything that isn't sucuri
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# other nginx config
As this was below the already configured:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29;
Magento 1
So long as the code uses the core method:
Mage::helper('core/http')->getRemoteAddr()
You can add a list of headers to app/etc/local.xml
inside of config->global
node that are used to determine the "real" ip. Something like:
<remote_addr_headers>
<header1>HTTP_X_SUCURI_CLIENTIP</header1>
<header2>HTTP_X_REAL_IP</header2>
<header3>HTTP_X_FORWARDED_FOR</header3>
</remote_addr_headers>
Then you can remove the real_ip_header
and set_real_ip_from
from the nginx config. Allowing all traffic not from Sucuri to be blocked and still able to obtain the true IP within magento. You can test this with something like:
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
Mage::app('admin');
print_r($_SERVER);
echo 'address: '.Mage::helper('core/http')->getRemoteAddr();
Magento 2
This appears to a little harder, I haven't dug as deep but on initial look.
- vendor/magento/framework/Session/Validator.php
is sensitive to configuration, on if it should use: http_x_forwarded_for
or remote_addr
- vendor/magento/framework/HTTP/PhpEnvironment/Request.php:725
has the method getClientIp
which appears to use the first it finds from HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, REMOTE_ADDR
- vendor/magento/magento2-base/pub/errors/processor.php:312
had the method _getClientIp
which uses REMOTE_ADDR
and if that isn't found returns undefined
I may be wrong but I haven't spotted anywhere a single value can be configured, or a list to try. So at this point would suggest adding something like the following to app/etc/bootstrap.php
$trustedIpHeaders = [
'HTTP_X_SUCURI_CLIENTIP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
];
$headersToPopulate = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
];
foreach($trustedIpHeaders as $trustedIpHeader)
if(isset($_SERVER[$trustedIpHeader]))
foreach($headersToPopulate as $headerToPopulate)
$_SERVER[$headerToPopulate] = $_SERVER[$trustedIpHeader]
break;
add a comment |
We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass"
location /
# Block everything that isn't sucuri
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# other nginx config
As this was below the already configured:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29;
Magento 1
So long as the code uses the core method:
Mage::helper('core/http')->getRemoteAddr()
You can add a list of headers to app/etc/local.xml
inside of config->global
node that are used to determine the "real" ip. Something like:
<remote_addr_headers>
<header1>HTTP_X_SUCURI_CLIENTIP</header1>
<header2>HTTP_X_REAL_IP</header2>
<header3>HTTP_X_FORWARDED_FOR</header3>
</remote_addr_headers>
Then you can remove the real_ip_header
and set_real_ip_from
from the nginx config. Allowing all traffic not from Sucuri to be blocked and still able to obtain the true IP within magento. You can test this with something like:
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
Mage::app('admin');
print_r($_SERVER);
echo 'address: '.Mage::helper('core/http')->getRemoteAddr();
Magento 2
This appears to a little harder, I haven't dug as deep but on initial look.
- vendor/magento/framework/Session/Validator.php
is sensitive to configuration, on if it should use: http_x_forwarded_for
or remote_addr
- vendor/magento/framework/HTTP/PhpEnvironment/Request.php:725
has the method getClientIp
which appears to use the first it finds from HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, REMOTE_ADDR
- vendor/magento/magento2-base/pub/errors/processor.php:312
had the method _getClientIp
which uses REMOTE_ADDR
and if that isn't found returns undefined
I may be wrong but I haven't spotted anywhere a single value can be configured, or a list to try. So at this point would suggest adding something like the following to app/etc/bootstrap.php
$trustedIpHeaders = [
'HTTP_X_SUCURI_CLIENTIP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
];
$headersToPopulate = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
];
foreach($trustedIpHeaders as $trustedIpHeader)
if(isset($_SERVER[$trustedIpHeader]))
foreach($headersToPopulate as $headerToPopulate)
$_SERVER[$headerToPopulate] = $_SERVER[$trustedIpHeader]
break;
We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass"
location /
# Block everything that isn't sucuri
allow 192.88.134.0/23;
allow 185.93.228.0/22;
allow 2a02:fe80::/29;
allow 66.248.200.0/22;
deny all;
# other nginx config
As this was below the already configured:
# Define header with original client IP
real_ip_header X-Forwarded-For;
# Define trusted IPs
set_real_ip_from 192.88.134.0/23;
set_real_ip_from 185.93.228.0/22;
set_real_ip_from 66.248.200.0/22;
set_real_ip_from 2a02:fe80::/29;
Magento 1
So long as the code uses the core method:
Mage::helper('core/http')->getRemoteAddr()
You can add a list of headers to app/etc/local.xml
inside of config->global
node that are used to determine the "real" ip. Something like:
<remote_addr_headers>
<header1>HTTP_X_SUCURI_CLIENTIP</header1>
<header2>HTTP_X_REAL_IP</header2>
<header3>HTTP_X_FORWARDED_FOR</header3>
</remote_addr_headers>
Then you can remove the real_ip_header
and set_real_ip_from
from the nginx config. Allowing all traffic not from Sucuri to be blocked and still able to obtain the true IP within magento. You can test this with something like:
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
Mage::app('admin');
print_r($_SERVER);
echo 'address: '.Mage::helper('core/http')->getRemoteAddr();
Magento 2
This appears to a little harder, I haven't dug as deep but on initial look.
- vendor/magento/framework/Session/Validator.php
is sensitive to configuration, on if it should use: http_x_forwarded_for
or remote_addr
- vendor/magento/framework/HTTP/PhpEnvironment/Request.php:725
has the method getClientIp
which appears to use the first it finds from HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, REMOTE_ADDR
- vendor/magento/magento2-base/pub/errors/processor.php:312
had the method _getClientIp
which uses REMOTE_ADDR
and if that isn't found returns undefined
I may be wrong but I haven't spotted anywhere a single value can be configured, or a list to try. So at this point would suggest adding something like the following to app/etc/bootstrap.php
$trustedIpHeaders = [
'HTTP_X_SUCURI_CLIENTIP',
'HTTP_X_REAL_IP',
'HTTP_X_FORWARDED_FOR',
];
$headersToPopulate = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
];
foreach($trustedIpHeaders as $trustedIpHeader)
if(isset($_SERVER[$trustedIpHeader]))
foreach($headersToPopulate as $headerToPopulate)
$_SERVER[$headerToPopulate] = $_SERVER[$trustedIpHeader]
break;
answered Apr 24 at 12:22
AdamAdam
213
213
add a comment |
add a comment |
For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php:
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']))
{
$_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
add a comment |
For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php:
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']))
{
$_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
add a comment |
For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php:
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']))
{
$_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php:
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']))
{
$_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
answered Mar 11 '18 at 21:58
ShakamalShakamal
388
388
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f216873%2fhow-to-get-real-ip-from-behind-sucuri-firewall%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does that mean the users' real IP is now received in the $_SERVER variable under the header $_SERVER['HTTP_X_FORWARDED_FOR'] whereas the $_SERVER[“REMOTE_ADDR”] is the WAF IP(Web Application Firewall IP) - If yes, Magento can be configured to work correctly.
– Dilhan Maduranga
Mar 11 '18 at 15:15
Can you elaborate and explain how please?
– Shakamal
Mar 11 '18 at 19:30