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 error response not redirectable when client is unauthorized #1435

Conversation

linhdangduy
Copy link
Contributor

@linhdangduy linhdangduy commented Aug 2, 2020

Summary

  1. Fix bug: unauthorized_client error on pre_authorization may be returned by redirection to client.

As rfc6749 has mentioned, when client is invalid, it MUST_NOT redirect the user-agent: https://tools.ietf.org/html/rfc6749#section-4.1.2.1

If the request fails due to a missing, invalid, or mismatching
redirection URI, or if the client identifier is missing or invalid,
the authorization server SHOULD inform the resource owner of the
error and MUST NOT automatically redirect the user-agent to the
invalid redirection URI.

Other Information

  • reordering the validate_resource_owner_authorize_for_client in pre_authorization as order of validate declaration. lib/doorkeeper/oauth/pre_authorization.rb
  • delete duplicated rspecs, and unnecessary rspecs on pre_authorization_spec.

spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/error_response_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/error_response_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/error_response_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/error_response_spec.rb Outdated Show resolved Hide resolved
@linhdangduy linhdangduy changed the title Not redirectable when client is unauthorized Make error response not redirectable when client is unauthorized Aug 2, 2020
@linhdangduy linhdangduy force-pushed the not_redirectable_when_client_is_unauthorized branch from 4b2c686 to dfe291b Compare August 2, 2020 09:33
spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
@linhdangduy linhdangduy force-pushed the not_redirectable_when_client_is_unauthorized branch from dfe291b to 5df890e Compare August 2, 2020 09:37
Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

Looks good so far 👍

:unauthorized
else
:bad_request
end
end

def redirectable?
name != :invalid_redirect_uri && name != :invalid_client &&
name != :invalid_redirect_uri &&
Copy link
Member

Choose a reason for hiding this comment

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

Let's introduce a const named NON_REDIRECTABLE_STATES or smth like this with states from above and then just:

NON_REDIRECTABLE_STATES.include?(name)

@linhdangduy linhdangduy force-pushed the not_redirectable_when_client_is_unauthorized branch from 5df890e to 72914eb Compare August 4, 2020 00:28
@linhdangduy linhdangduy force-pushed the not_redirectable_when_client_is_unauthorized branch from 72914eb to bf9d348 Compare August 4, 2020 00:29
Comment on lines -43 to +45
name != :invalid_redirect_uri && name != :invalid_client &&
!URIChecker.oob_uri?(@redirect_uri)
!NON_REDIRECTABLE_STATES.include?(name) && !URIChecker.oob_uri?(@redirect_uri)
Copy link
Contributor Author

@linhdangduy linhdangduy Aug 4, 2020

Choose a reason for hiding this comment

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

@nbulaj I added these error names to NON_REDIRECTABLE_STATES

@nbulaj nbulaj merged commit d8761e0 into doorkeeper-gem:master Aug 4, 2020
@nbulaj
Copy link
Member

nbulaj commented Aug 4, 2020

Thanks @linhdangduy !

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.

3 participants