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

Make AuthenticationFailed more specific for bad headers/expired tokens #16

Merged
merged 1 commit into from
Nov 5, 2015
Merged

Make AuthenticationFailed more specific for bad headers/expired tokens #16

merged 1 commit into from
Nov 5, 2015

Conversation

edmorley
Copy link
Contributor

Whilst many of the possible mohawk exception types should not be revealed directly in the AuthenticationFailed exception message (since they would give clues to attackers - eg let them determine valid client ids), there are some that are useful (and safe) to surface in the response to the client.

Fixes #14.

The existing tests for the "dangerous to reveal" cases have also been updated to ensure they exact-match against the string, since previously they were only checking for the substring (since assertRaisesRegexp() uses re.search()).

@@ -97,7 +97,7 @@ def test_hawk_post_wrong_sig(self):
method=method)

self.assertRaisesRegexp(AuthenticationFailed,
'Hawk authentication failed',
'^Hawk authentication failed$',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

@kumar303
Copy link
Owner

Could you add some tests for the BadHeaderValue and TokenExpire cases that check the exception message? They don't have to be exact, something like

self.assertRaisesRegexp(
    AuthenticationFailed, 
    '^Hawk authentication failed: The token has expired .*')

These will serve two purposes: 1) they'll make sure we don't regress showing extra output in special cases and 2) they'll cover the else blocks in these cases so that no exceptions get raised by future refactoring.

@kumar303
Copy link
Owner

There are no existing tests for the bad header and bad timestamp cases or I would have updated those too

They should be easy to add. I'd suggest copying test_hawk_post_wrong_sig but use mock to patch Receiver() and give it a side_effect for each exception. Let me know if you get stuck. Because of how mock patching works you may need to edit the code to do receiver = mohawk.Receiver so you can patch 'mohawk.Receiver' (i.e. a direct reference).

Whilst many of the possible mohawk exception types should not be
revealed directly in the AuthenticationFailed exception message (since
they would give clues to attackers - eg let them determine valid client
ids), there are some that are useful (and safe) to surface in the
response to the client.

Fixes #14.
@edmorley
Copy link
Contributor Author

edmorley commented Nov 4, 2015

PR updated with tests :-)

I ended up not mocking Receiver in the end, since it was easy to do without, and this way we ensure that mohawk still raises those exceptions for the specific cases we expect.

@kumar303
Copy link
Owner

kumar303 commented Nov 5, 2015

Awesome, thanks! The added tests look great.

kumar303 added a commit that referenced this pull request Nov 5, 2015
Make AuthenticationFailed more specific for bad headers/expired tokens
@kumar303 kumar303 merged commit 55889a0 into kumar303:master Nov 5, 2015
@edmorley edmorley deleted the less-generic-exception-messages branch November 5, 2015 23:27
@edmorley
Copy link
Contributor Author

edmorley commented Nov 8, 2015

Thank you :-)

@edmorley
Copy link
Contributor Author

@kumar303 - would it be possible to make a new release for this at some point in the next week or two? :-)

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

Successfully merging this pull request may close these issues.

None yet

2 participants