Skip to content

Commit 23fb2a2

Browse files
committed
Fixed decoding of auth_string to avoid errors:
To avoid TypeError and UnicodeDecodeError, added try ... except block. It will return False when decoding failed
1 parent ff72813 commit 23fb2a2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ def _authenticate_basic_auth(self, request):
5454

5555
encoding = request.encoding or 'utf-8'
5656

57-
auth_string_decoded = base64.b64decode(auth_string).decode(encoding)
57+
try:
58+
b64_decoded = base64.b64decode(auth_string)
59+
except TypeError:
60+
log.debug("Failed basic auth: %s can't be decoded as base64", auth_string)
61+
return False
62+
63+
try:
64+
auth_string_decoded = b64_decoded.decode(encoding)
65+
except UnicodeDecodeError:
66+
log.debug("Failed basic auth: %s can't be decoded as unicode by %s",
67+
auth_string,
68+
encoding)
69+
return False
70+
5871
client_id, client_secret = map(unquote_plus, auth_string_decoded.split(':', 1))
5972

6073
if self._load_application(client_id, request) is None:

0 commit comments

Comments
 (0)