From 010221ab5b3b8e2e994897a9811e7bba4333c958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 29 Jan 2020 11:35:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20handling=20of=20unset=20re?= =?UTF-8?q?mote=20addresses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/util/flask.py | 3 ++- src/octoprint/util/net.py | 4 ++++ tests/util/test_net.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index be41588cb..11e5ebfe3 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -584,7 +584,8 @@ def passive_login(): elif settings().getBoolean(["accessControl", "autologinLocal"]) \ and settings().get(["accessControl", "autologinAs"]) is not None \ and settings().get(["accessControl", "localNetworks"]) is not None \ - and not "active_logout" in flask.request.cookies: + and not "active_logout" in flask.request.cookies \ + and remote_address: # attempt local autologin autologin_as = settings().get(["accessControl", "autologinAs"]) local_networks = _local_networks() diff --git a/src/octoprint/util/net.py b/src/octoprint/util/net.py index c0f123f58..7526323a2 100644 --- a/src/octoprint/util/net.py +++ b/src/octoprint/util/net.py @@ -45,6 +45,10 @@ else: HAS_V6 = False def is_lan_address(address, additional_private=None): + if not address: + # no address is LAN address + return True + try: address = unmap_v4_as_v6(address) address = strip_interface_tag(address) diff --git a/tests/util/test_net.py b/tests/util/test_net.py index 438fea4be..9be4d8853 100644 --- a/tests/util/test_net.py +++ b/tests/util/test_net.py @@ -44,7 +44,8 @@ class UtilNetTest(unittest.TestCase): ("11.1.2.3", ["11/8"], True), ("12.1.1.123", [], True), ("2a01:4f8:1c0c:6958::1:23", [], True), - ("fe80::89f3:31bb:ced0:2093%wlan0", [], True) + ("fe80::89f3:31bb:ced0:2093%wlan0", [], True), + (None, [], True) ) @ddt.unpack @mock.patch("netifaces.interfaces", side_effect=patched_interfaces)