-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make error response not redirectable when client is unauthorized #1435
Conversation
4b2c686
to
dfe291b
Compare
dfe291b
to
5df890e
Compare
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.
Looks good so far 👍
:unauthorized | ||
else | ||
:bad_request | ||
end | ||
end | ||
|
||
def redirectable? | ||
name != :invalid_redirect_uri && name != :invalid_client && | ||
name != :invalid_redirect_uri && |
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.
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)
5df890e
to
72914eb
Compare
72914eb
to
bf9d348
Compare
name != :invalid_redirect_uri && name != :invalid_client && | ||
!URIChecker.oob_uri?(@redirect_uri) | ||
!NON_REDIRECTABLE_STATES.include?(name) && !URIChecker.oob_uri?(@redirect_uri) |
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.
@nbulaj I added these error names to NON_REDIRECTABLE_STATES
Thanks @linhdangduy ! |
Summary
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
return status code as 401 when error is unauthorized_client lib/doorkeeper/oauth/error_response.rb
add
name != :unauthorized_client &&
toredirectable?
method of error_response lib/doorkeeper/oauth/error_response.rbadd unit test on
redirectable?
for error_response_spec and invalid_request_response_spec spec/lib/oauth/error_response_spec.rb, spec/lib/oauth/invalid_request_response_spec.rbadd test
must call the validations on client and redirect_uri before other validations because they are not redirectable
to pre_authorization_spec. spec/lib/oauth/pre_authorization_spec.rbmissing parameter response_type
andinvalid_redirect_uri
, if themissing parameter response_type
validation is run beforeinvalid_redirect_uri
validation, authorization server will return error by redirect the user-agent to the invalid redirect_uri, which is not followed quote from rfc6749 above (which lead to vulnerability on redirection)Other Information
validate_resource_owner_authorize_for_client
in pre_authorization as order of validate declaration. lib/doorkeeper/oauth/pre_authorization.rb