IP Proxy bug avec l’extension Atos pour Magento
Lors de la construction de la requête l’adresse IP du client est envoyé. Pour les personnes derrière un Proxy l’IP généré via HTTP_X_FORWARDED_FOR est de type “XXX.XXX.XXX.XXX, XXX.XXX.XXX.XXX” (IP du client et du Proxy) et non “XXX.XXX.XXX.XXX”. Cela entraîne un plantage du module lors de la redirection (page blanche).
Le patch suivant filtre les IP récupérées par la méthode Mage_Atos_Model_Api_Paramaters::getIpAddress et récupére uniquement la seconde quand une liste est fournie.
Pour l’utiliser, il faut le copier sur le serveur, le renommer en proxy.patch.
Puis à la racine de magento, exécuter :
patch -p0 < /cheminverslefichier/proxy.patch
Enfin, ne pas oublier de vider le cache Magento.
Contenu du fichier :
Index: app/code/local/Mage/Atos/Model/Api/Parameters.php
===================================================================
--- app/code/local/Mage/Atos/Model/Api/Parameters.php (revision 1644)
+++ app/code/local/Mage/Atos/Model/Api/Parameters.php (working copy)
@@ -138,6 +135,30 @@
}
}
+ # Determine originating IP address. REMOTE_ADDR is the standard
+ # but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
+ # HTTP_X_FORWARDED_FOR are set by proxies so check for these before
+ # falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma-
+ # delimited list in the case of multiple chained proxies; the first is
+ # the originating IP.
+ #
+ # Security note: do not use if IP spoofing is a concern for your
+ # application. Since remote_ip checks HTTP headers for addresses forwarded
+ # by proxies, the client may send any IP. remote_addr can't be spoofed but
+ # also doesn't work behind a proxy, since it's always the proxy's IP.
+ # @see http://metautonomo.us/2008/05/30/the-local_request-that-isnt/
+ $reg_priv_network = '/^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i';
+ if ( strpos($ip, ',') !== false ) {
+ $_ips = explode(',', $ip);
+
+ foreach ( $_ips as $_ip ) {
+ $_ip = trim($_ip);
+ if ( !preg_match($reg_priv_network, $_ip, $matches ) ) {
+ return $_ip;
+ }
+ }
+ }
+
return $ip;
}