You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is in rest_framework.authentication.BasicAuthentication.authenticate. The call to base64.b64decode does not catch binascii.Error, which can be raised by binascii.a2b_base64
This assumes we want to handle that error and not let it propagate up the stack. I can't think of any reason not to, specially considering the raised exception message:
Invalid basic header. Credentials not correctly base64 encoded.
Stacktrace
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/views.py", line 466, in dispatch
response = self.handle_exception(exc)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/views.py", line 454, in dispatch
self.initial(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/views.py", line 376, in initial
self.perform_authentication(request)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/views.py", line 310, in perform_authentication
request.user
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/request.py", line 353, in __getattribute__
return super(Request, self).__getattribute__(attr)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/request.py", line 193, in user
self._authenticate()
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/request.py", line 316, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "/app/.heroku/python/lib/python3.4/site-packages/rest_framework/authentication.py", line 78, in authenticate
auth_parts = base64.b64decode(auth[1]).decode(HTTP_HEADER_ENCODING).partition(':')
File "/app/.heroku/python/lib/python3.4/base64.py", line 90, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Checklist
I have verified that that issue exists against the master branch of Django REST framework.
I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
This is not a usage question. (Those should be directed to the discussion group instead.)
The problem is in
rest_framework.authentication.BasicAuthentication.authenticate
. The call tobase64.b64decode
does not catchbinascii.Error
, which can be raised bybinascii.a2b_base64
This assumes we want to handle that error and not let it propagate up the stack. I can't think of any reason not to, specially considering the raised exception message:
Stacktrace
Checklist
master
branch of Django REST framework.The text was updated successfully, but these errors were encountered: