From d6d7b5fa729e940de16d2b34f2cf9531339f724e Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Mon, 13 May 2019 09:42:28 -0700 Subject: [PATCH hyperkitty] Treat all exceptions from is_robot() as a robot. is_robot() only throws exceptions in case of invalid input, which in this part of Hyperkitty can only happen as a result of a programming error. I.e., since this pulls directly from request.META there is no way for an invalid type to occur, unless the application's source code were to change at some point in the future. However, as a defensive measure, the error can be papered over by treating any exceptions thrown by is_robot() as defaulting to be a bot. "To Err is Human; To Really Foul Things Up Requires a Bot". Signed-off-by: Bryce Harrington --- hyperkitty/views/thread.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py index de5b12c..8ede245 100644 --- a/hyperkitty/views/thread.py +++ b/hyperkitty/views/thread.py @@ -152,7 +152,11 @@ def thread_index(request, mlist_fqdn, threadid, month=None, year=None): # http://djangosnippets.org/snippets/1865/ user_agent = request.META.get('HTTP_USER_AGENT', None) if user_agent: - is_bot = robot_detection.is_robot(user_agent) + try: + is_bot = robot_detection.is_robot(user_agent) + except: + # This should not fail, but if it does assume a bot is involved... + is_bot = True else: is_bot = True -- 2.17.1