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

Ensure that the native redirect_uri parameter matches with redirect_uri of the client. #1060

Conversation

hallucinations
Copy link
Contributor

Summary

Even though #1045 fixes the issue with broken native redirect URLs, it bypasses
Doorkeeper::OAuth::Helpers::URIChecker::valid_for_authorization? check for
authorization_code grants. This enables Doorkeeper:: OAuth::AuthorizationCodeRequest#validate_redirect_uri to return true if the
redirect_uri parameter is a native URI.

This fix tries to fix this anomaly by changing the behaviour of
Doorkeeper::OAuth::Helpers::URIChecker::valid? to return true whenever the
redirect_uri parameter is a native URI. I think this makes more sense because
this is a logic that is common to all grant types.

Other Information

When Doorkeeper::OAuth::Helpers::URIChecker::valid? returns true for native
URLs, Doorkeeper::OAuth::Helpers::URIChecker::valid_for_authorization? makes
sure that the given two urls match before returning true to the respective
validate_redirect_uri methods of different grant types.

Also gets rid of a #TODO from Doorkeeper::OAuth::PreAuthorization.

def validate_redirect_uri
return false if redirect_uri.blank?

Helpers::URIChecker.native_uri?(redirect_uri) ||
Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uri)
Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uri)

Choose a reason for hiding this comment

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

Line is too long. [87/80]

Even though doorkeeper-gem#1045 fixes the issue with broken native redirect URLs, it bypasses
`Doorkeeper::OAuth::Helpers::URIChecker::valid_for_authorization?` check for
authorization_code grants. This enables `Doorkeeper::
OAuth::AuthorizationCodeRequest#validate_redirect_uri` to return `true` if the
`redirect_uri` parameter is a native URI.

This fix tries to fix this anomaly by changing the behaviour of
`Doorkeeper::OAuth::Helpers::URIChecker::valid?` to return `true` whenever the
`redirect_uri` parameter is a native URI. I think this makes more sense because
this is a logic that is common to all grant types.

When `Doorkeeper::OAuth::Helpers::URIChecker::valid?` returns `true` for native
URLs, `Doorkeeper::OAuth::Helpers::URIChecker::valid_for_authorization?` makes
sure that the given two urls match before returning `true` to the respective
`validate_redirect_uri` methods of different grant types.

Also gets rid of a #TODO from `Doorkeeper::OAuth::PreAuthorization`.

Update News.md with the change

Address review
@hallucinations hallucinations force-pushed the feature/ensure-native-redirect_uri-matches-with-grant-redirect_uri branch from f249d66 to bb90fe1 Compare March 20, 2018 16:27
@nbulaj nbulaj merged commit bc8930c into doorkeeper-gem:master Mar 21, 2018
@nbulaj nbulaj added this to the 5.0 milestone Mar 29, 2018
@hallucinations hallucinations deleted the feature/ensure-native-redirect_uri-matches-with-grant-redirect_uri branch April 4, 2018 08:36
Gargron pushed a commit to mastodon/mastodon that referenced this pull request May 12, 2018
ryansch added a commit to outstand/doorkeeper that referenced this pull request Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants