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

Misleading method name with "magic" fallback #718

Open
polamayster opened this issue Mar 6, 2020 · 1 comment
Open

Misleading method name with "magic" fallback #718

polamayster opened this issue Mar 6, 2020 · 1 comment

Comments

@polamayster
Copy link
Contributor

polamayster commented Mar 6, 2020

def get_token_from_header(request):
"""
Helper function to extract a token from the request header.
:param request: OAuthlib request.
:type request: oauthlib.common.Request
:return: Return the token or None if the Authorization header is malformed.
"""
token = None
if 'Authorization' in request.headers:
split_header = request.headers.get('Authorization').split()
if len(split_header) == 2 and split_header[0].lower() == 'bearer':
token = split_header[1]
else:
token = request.access_token
return token

It would be much more predictable/cleaner if method either did not fallback to body payload/uri_query on line 255:
else:
token = request.access_token

or method was renamed to reflect what it actually does.

Paranoiac mode on: security issue can slip in with a misuse as token in headers is for authorization of the request and token in payload is for introspection/revoke/refresh and can be accidentally used to authorize request itself:

def validate_request(self, request):
"""
:param request: OAuthlib request.
:type request: oauthlib.common.Request
"""
token = get_token_from_header(request)
return self.request_validator.validate_bearer_token(
token, request.scopes, request)

@JonathanHuot
Copy link
Member

JonathanHuot commented Mar 13, 2020

Yes you're right, I think this part of the code deserves a refactoring to allow #609 , which is essential to progress on the different ways of client authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants