-
-
Notifications
You must be signed in to change notification settings - Fork 802
Fix: Handle AttributeError in IntrospectTokenView #1562
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
base: master
Are you sure you want to change the base?
Fix: Handle AttributeError in IntrospectTokenView #1562
Conversation
Contribution guideline says
but I do not have permission to set assignee. |
I'm not 100% sure this is the correct handling. Per https://datatracker.ietf.org/doc/html/rfc7662#section-2.3,
I'm not sure that a missing token would qualify as properly formed. I feel that a 400 might be the proper response in this case since the request is missing the required 'token' parameter. My instinct says a present, but invalid or blank token, i.e. a body of
would return an |
for more information, see https://pre-commit.ci
….com:dawidwolski-identt/django-oauth-toolkit into handle_attribute_error_in_get_token_response
for more information, see https://pre-commit.ci
@dopry I agree with you. I've changed the response to follow https://datatracker.ietf.org/doc/html/rfc6749#section-5.2 |
@@ -35,6 +35,11 @@ def get_token_response(token_value=None): | |||
) | |||
except ObjectDoesNotExist: | |||
return JsonResponse({"active": False}, status=200) | |||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if something other than the token raised the attribute error? Is there a way to proactively test the token so we avoid the overhead of exception handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to change the error message to be more generic and fix the bug that causes the app to crash. Then, if necessary, specify a message. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to check if a token was provided before get_token_response is called? Are there existing hooks for validation where this could be caught in advance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a proper place to check for the presence of a token. It's the first place where the token is accessed. To move this check one level up, we can use request.GET.get("token", None)
without a default, but then we need to handle the missing token twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see both get and post return self.get_token_response(request.[GET|POST].get("token", None))
Why not check if token_value is None:
before calculating a checksum, rather than waiting on token_value.encode
to raise an AttributeError
and avoid the overhead of handling an exception unnecessarily.
Description of the Change
Handle
AttributeError
inget_token_response
. If there is notoken
parameter in introspect endpoints they raiseAttributeError
.Checklist
CHANGELOG.md
updated (only for user relevant changes)AUTHORS