-
Notifications
You must be signed in to change notification settings - Fork 13
fix: Handle malformed auth header #122
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
Conversation
smholloway
left a comment
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.
👍 Nice!
| ) | ||
| ) | ||
| try: | ||
| collected_request_parameters = dict( |
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.
Does this raise a different exception type? I'm thinking that we won't be able to differentiate between missing auth headers and malformed ones anymore, something that I'm pretty sure we'll still want.
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.
Here's the path I went down here:
- A "Malformed authorization header" currently raises a
ValueErrorfromoauthlibwhich is not caught anywhere: oauthlib:parse_authorization_header - DDA attempts to massage most OAuth errors into "those specified in the OAuth Problem Reporting proposal", here, which is what our service expects in the place this bubbles up
- Looking through that list of errors, I figured
OAuthMissingParameterErrorwas still the best fit in this case.
Do we currently detect a missing Authorization header intelligently?
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.
In this case it's missing all the needed parameters, and so the error lists them all.
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.
Right, so that would work in this case. However, if there's a case where we're getting an invalid auth header (anything that doesn't conform explicitly to OAuth as defined here), it'll get swallowed up as a missing error. I think those two cases should be distinguished from one another.
Optimally, I think that oauthlib would report oauth_parameters_rejected (defined in OAuth error reporting) rather than simply a ValueError but it wasn't implemented that way. I think that the best thing to do would be to add support for token_revoked in build_error and handle that case when we get a ValueError from collect_parameters. That way, the caller can clearly see the difference between missing and invalid parameters.
We can also add an explicit check for all parameters missing case you mentioned here too in order to catch that case.
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.
After discussion in Slack - I'm returning parameter_rejected
Handle "Malformed authorization header"
ValueErrorthat bubbles up fromoauthlibthe same way we handle other oauth errorsFix a docstring typo
Update CHANGELOG.md
Update README.md (as needed)
New dependencies were added to
pyproject.tomlpip installsucceeds with a clean virtualenvThere are new or modified tests that cover changes
Test coverage is maintained or expanded