Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
e19b21ec
Commit
e19b21ec
authored
May 03, 2016
by
Germán Larraín
Committed by
Tom Christie
May 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle incorrectly padded HTTP basic auth header (#4090)
parent
a9bbb502
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletions
+10
-1
rest_framework/authentication.py
+2
-1
tests/test_authentication.py
+8
-0
No files found.
rest_framework/authentication.py
View file @
e19b21ec
...
...
@@ -4,6 +4,7 @@ Provides various authentication policies.
from
__future__
import
unicode_literals
import
base64
import
binascii
from
django.contrib.auth
import
authenticate
,
get_user_model
from
django.middleware.csrf
import
CsrfViewMiddleware
...
...
@@ -77,7 +78,7 @@ class BasicAuthentication(BaseAuthentication):
try
:
auth_parts
=
base64
.
b64decode
(
auth
[
1
])
.
decode
(
HTTP_HEADER_ENCODING
)
.
partition
(
':'
)
except
(
TypeError
,
UnicodeDecodeError
):
except
(
TypeError
,
UnicodeDecodeError
,
binascii
.
Error
):
msg
=
_
(
'Invalid basic header. Credentials not correctly base64 encoded.'
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
...
...
tests/test_authentication.py
View file @
e19b21ec
...
...
@@ -85,6 +85,14 @@ class BasicAuthTests(TestCase):
response
=
self
.
csrf_client
.
post
(
'/basic/'
,
{
'example'
:
'example'
},
format
=
'json'
,
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
def
test_regression_handle_bad_base64_basic_auth_header
(
self
):
"""Ensure POSTing JSON over basic auth with incorrectly padded Base64 string is handled correctly"""
# regression test for issue in 'rest_framework.authentication.BasicAuthentication.authenticate'
# https://github.com/tomchristie/django-rest-framework/issues/4089
auth
=
'Basic =a='
response
=
self
.
csrf_client
.
post
(
'/basic/'
,
{
'example'
:
'example'
},
format
=
'json'
,
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
def
test_post_form_failing_basic_auth
(
self
):
"""Ensure POSTing form over basic auth without correct credentials fails"""
response
=
self
.
csrf_client
.
post
(
'/basic/'
,
{
'example'
:
'example'
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment