Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch padding errors when base64 decoding client secrets #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions provider/oauth2/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import base64

from ..utils import now
from .forms import ClientAuthForm
from .models import AccessToken
Expand Down Expand Up @@ -28,8 +30,8 @@ def authenticate(self, request=None):
return None

try:
basic, base64 = auth.split(' ')
client_id, client_secret = base64.decode('base64').split(':')
basic, base64_encoded_secret = auth.split(' ')
client_id, client_secret = base64_encoded_secret.decode('base64').split(':')

form = ClientAuthForm({
'client_id': client_id,
Expand All @@ -39,6 +41,9 @@ def authenticate(self, request=None):
return form.cleaned_data.get('client')
return None

except base64.binascii.Error:
# Auth header did not have proper base64 padding
return None
except ValueError:
# Auth header was malformed, unpacking went wrong
return None
Expand Down