From 38261b523560caa71ce35d65750dd6ceae3f41c5 Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 20 Nov 2015 11:13:44 +0100 Subject: [PATCH 1/2] check if the auth type is Basic before getting the user name fix #1148 --- gunicorn/glogging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index 3a4ba686..d8241449 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -381,7 +381,7 @@ class Logger(object): def _get_user(self, environ): user = None http_auth = environ.get("HTTP_AUTHORIZATION") - if http_auth: + if http_auth and http_auth.startswith('Basic'): auth = http_auth.split(" ", 1) if len(auth) == 2: try: From 45f008187b352a50425f662973888a38dd8e5bd8 Mon Sep 17 00:00:00 2001 From: benoitc Date: Sat, 21 Nov 2015 10:19:06 +0100 Subject: [PATCH 2/2] also ignore binascii error when decoding the user in access log --- gunicorn/glogging.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index d8241449..018e7eca 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -4,6 +4,7 @@ # See the NOTICE for more information. import base64 +import binascii import time import logging logging.Logger.manager.emittedNoHandlerWarning = 1 @@ -394,6 +395,9 @@ class Logger(object): except TypeError as exc: self.debug("Couldn't get username: %s", exc) return user + except binascii.Error as exc: + self.debug("Couldn't get username: %s", exc) + return user if len(auth) == 2: user = auth[0] return user