Skip to content

Commit cc86f9a

Browse files
committed
Capture real IP behind firewalls and proxies.
1 parent 9c1a8f3 commit cc86f9a

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ Revision History for FraudLabs Pro Magento2
2424
Changed plugin configuration setting.
2525

2626
2.0.11 2018-07-24
27-
Fix compatibility issue.
27+
Fix compatibility issue.
28+
29+
2.0.12 2019-02-21
30+
Capture real IP behind firewalls and proxies.

Controller/Observer.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,35 @@ public function processSendRequestToFraudLabsPro($order) {
8080
$rejectStatus = $this->scopeConfig->getValue('fraudlabspro/active_display/reject_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
8181

8282
$billingAddress = $order->getBillingAddress();
83+
8384
$ip = $_SERVER['REMOTE_ADDR'];
85+
$headers = array(
86+
'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_INCAP_CLIENT_IP', 'HTTP_X_SUCURI_CLIENTIP'
87+
);
8488

85-
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && filter_var($_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP)) {
86-
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
89+
foreach ($headers as $header) {
90+
if (isset($_SERVER[$header]) && filter_var($_SERVER[$header], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
91+
$ip = $_SERVER[$header];
92+
}
8793
}
8894

89-
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
95+
// get the data of all ips
96+
$ip_sucuri = $ip_incap = $ip_cf = $ip_forwarded = '::1';
97+
$ip_remoteadd = $_SERVER['REMOTE_ADDR'];
98+
if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']) && filter_var($_SERVER['HTTP_X_SUCURI_CLIENTIP'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)){
99+
$ip_sucuri = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
100+
}
101+
if(isset($_SERVER['HTTP_INCAP_CLIENT_IP']) && filter_var($_SERVER['HTTP_INCAP_CLIENT_IP'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)){
102+
$ip_incap = $_SERVER['HTTP_INCAP_CLIENT_IP'];
103+
}
104+
if(isset($_SERVER['HTTP_CF_CONNECTING_IP']) && filter_var($_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)){
105+
$ip_cf = $_SERVER['HTTP_CF_CONNECTING_IP'];
106+
}
107+
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
90108
$xip = trim(current(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])));
91109

92110
if (filter_var($xip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
93-
$ip = $xip;
111+
$ip_forwarded = $xip;
94112
}
95113
}
96114

@@ -109,6 +127,11 @@ public function processSendRequestToFraudLabsPro($order) {
109127
'format' => 'json',
110128
'key' => $apiKey,
111129
'ip' => $ip,
130+
'ip_remoteadd' => $ip_remoteadd,
131+
'ip_sucuri' => $ip_sucuri,
132+
'ip_incap' => $ip_incap,
133+
'ip_forwarded' => $ip_forwarded,
134+
'ip_cf' => $ip_cf,
112135
'first_name' => $billingAddress->getFirstname(),
113136
'last_name' => $billingAddress->getLastname(),
114137
'bill_addr' => implode(" ", $billingAddress->getStreet()),
@@ -128,7 +151,7 @@ public function processSendRequestToFraudLabsPro($order) {
128151
'payment_mode' => $paymentMode,
129152
'flp_checksum' => ( isset( $_COOKIE['flp_checksum'] ) ) ? $_COOKIE['flp_checksum'] : '',
130153
'source' => 'magento',
131-
'source_version' => '2.0.11',
154+
'source_version' => '2.0.12',
132155
);
133156

134157
$shippingAddress = $order->getShippingAddress();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hexasoft/module-fraudlabspro",
33
"description": "FraudLabs Pro Fraud Prevention plugin that screen the order transaction for online frauds. Fraud Prevention extension for Magento 2.",
4-
"version": "2.0.11",
4+
"version": "2.0.12",
55
"type": "magento2-module",
66
"require": {
77
"php": "~5.5.0|~5.6.0|~7.0"

0 commit comments

Comments
 (0)