From 05eded4e281bf1a152134c25b4bdba7494d730c0 Mon Sep 17 00:00:00 2001 From: Liljack118 Date: Sat, 3 Dec 2022 15:38:14 +0100 Subject: [PATCH] replace partition with split in BasicAuthentication --- rest_framework/authentication.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 382abf158..3f3bd2227 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -78,12 +78,12 @@ class BasicAuthentication(BaseAuthentication): auth_decoded = base64.b64decode(auth[1]).decode('utf-8') except UnicodeDecodeError: auth_decoded = base64.b64decode(auth[1]).decode('latin-1') - auth_parts = auth_decoded.partition(':') - except (TypeError, UnicodeDecodeError, binascii.Error): + + userid, password = auth_decoded.split(':', 1) + except (TypeError, ValueError, UnicodeDecodeError, binascii.Error): msg = _('Invalid basic header. Credentials not correctly base64 encoded.') raise exceptions.AuthenticationFailed(msg) - userid, password = auth_parts[0], auth_parts[2] return self.authenticate_credentials(userid, password, request) def authenticate_credentials(self, userid, password, request=None):