[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Only check for loopback addresses when ignoring redirects



commit 1b5fc495111c2881c7e0e7575131a299dec3e3c7
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Wed Nov 23 16:38:58 2016 +0000

    Only check for loopback addresses when ignoring redirects
    
    * Also look for .local domains in redirects
---
 ooni/common/ip_utils.py | 23 +++++++++++++++++++----
 ooni/common/txextra.py  |  4 ++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/ooni/common/ip_utils.py b/ooni/common/ip_utils.py
index 8745b7a..afc5bf4 100644
--- a/ooni/common/ip_utils.py
+++ b/ooni/common/ip_utils.py
@@ -15,15 +15,30 @@ def is_private_ipv4_address(address):
     except AddressValueError:
         return False
 
-def is_private_address(address):
+
+def is_private_address(address, only_loopback=False):
+    """
+    Checks to see if an IP address is in private IP space and if the
+    hostname is either localhost or *.local.
+
+    :param address: an IP address of a hostname
+    :param only_loopback: will only check if the IP address is either
+        127.0.0.1/8 or ::1 in ipv6
+    :return: True if the IP address or host is in private space
+    """
     try:
         ip_address = IPv4Address(address)
     except AddressValueError:
         try:
             ip_address = IPv6Address(address)
         except AddressValueError:
+            if address == "localhost":
+                return True
+            elif address.endswith(".local"):
+                return True
             return False
 
-    return any(
-        [ip_address.is_private, ip_address.is_loopback]
-    )
+    candidates = [ip_address.is_loopback]
+    if not only_loopback:
+        candidates.append(ip_address.is_private)
+    return any(candidates)
diff --git a/ooni/common/txextra.py b/ooni/common/txextra.py
index 39b8996..e3507bf 100644
--- a/ooni/common/txextra.py
+++ b/ooni/common/txextra.py
@@ -198,8 +198,8 @@ class FixedRedirectAgent(BrowserLikeRedirectAgent):
             locationHeaders[0]
         )
         uri = client.URI.fromBytes(location)
-        if self.ignorePrivateRedirects and (is_private_address(uri.host) or
-                                            uri.host == "localhost"):
+        if self.ignorePrivateRedirects and is_private_address(uri.host,
+                                                              only_loopback=True):
             return response
 
         deferred = self._agent.request(method, location, headers)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits