diff --git a/src/bigbrother/ministry/ofcommunication.py b/src/bigbrother/ministry/ofcommunication.py index c29848ed..ed5b36a7 100644 --- a/src/bigbrother/ministry/ofcommunication.py +++ b/src/bigbrother/ministry/ofcommunication.py @@ -33,14 +33,14 @@ def detect_socket_leaks(socket_event): # validate is valid ip address (no hostname, etc) # raises NetworkLeak if not try: - ipaddress.ip_address(ip_address) + ip_address = ipaddress.ip_address(ip_address) except ValueError: logger.warn(f'Conn made to {ip_address} outside of Tor/similar') raise \ NetworkLeak('Conn to host/non local IP, this is a privacy issue!') # Validate that the IP is localhost ipv4 - - if not ip_address.startswith('127'): + if not ip_address.is_loopback and not ip_address.is_multicast \ + and not ip_address.is_private: logger.warn(f'Conn made to {ip_address} outside of Tor/similar') raise NetworkLeak('Conn to non local IP, this is a privacy concern!') diff --git a/tests/test_big_brother.py b/tests/test_big_brother.py index 2d5cbefa..45b03e60 100644 --- a/tests/test_big_brother.py +++ b/tests/test_big_brother.py @@ -22,6 +22,12 @@ class TestBigBrother(unittest.TestCase): bigbrother.enable_ministries() with self.assertRaises(onionrexceptions.NetworkLeak): requests.get('https://example.com') + with self.assertRaises(onionrexceptions.NetworkLeak): + requests.get('https://1.1.1.1/') + try: + requests.get('http://192.168.1.1/') + except requests.exceptions.ConnectionError: + pass unittest.main()