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

RFC8252#section-7.3 Loopback Interface Redirection #400

Merged
merged 3 commits into from
Mar 4, 2020

Conversation

raffis
Copy link
Contributor

@raffis raffis commented Mar 3, 2020

This implements support for a dynamic port request from an oauth2 client.
RFC reference: https://tools.ietf.org/html/rfc8252#section-7.3

Related issue

#284
ory/hydra#1732

Proposed changes

Checklist

  • I have read the contributing guidelines
  • I have read the security policy
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact security@ory.sh) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)

Further comments

The RFC (https://tools.ietf.org/html/rfc8252#section-7.3) states an URI like http://127.0.0.1:{port}/{path} and http://[::1]:{port}/{path}. I am not 100% sure if this is a must or just a regex example.
I have implemented this in fosil that it is now possible to register:

... and if a registered client has one or both of these redirect uri's a client may request a dynamic port onto the loopback interface. For example http://127.0.0.1:9988 or with a path http://127.0.0.1:9988/callback. Note as with this PR, if both IPv4 and IPv6 should be supported for redirect loopback uris the clients needs to be registered with both.

If the RFC requests that the redirect URI must exactly be http://127.0.0.1:{port}/{path} then more code needs to be changed, for example the client registration in hydra would also fail with this (invalid) uri.

@CLAassistant
Copy link

CLAassistant commented Mar 3, 2020

CLA assistant check
All committers have signed the CLA.

expected: "http://127.0.0.1:1024",
},
{
client: &DefaultClient{RedirectURIs: []string{"http://127.0.0.1"}},
Copy link
Member

Choose a reason for hiding this comment

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

I believe that this should fail because the whitelisted redirect URL does not have the /cb path segment. The spec only talks about randomly assigned ports but does not leave room for variable paths, if I understand correctly. Otherwise, this looks pretty good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds right. I had to change some bits because of that. Using url parse now to extract the paths and compare them.

@aeneasr
Copy link
Member

aeneasr commented Mar 4, 2020

You rock, thank you for your contribution!

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

One last change :)

// Loopback redirect URIs use the "http" scheme and are constructed with
// the loopback IP literal and whatever port the client is listening on.
func isMatchingRedirectURI(uri string, haystack []string) bool {
requested, err := url.Parse(strings.ToLower(uri))
Copy link
Member

Choose a reason for hiding this comment

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

Since we are now using url.Parse, toLower is no longer required and actually might cause issues for servers that have case sensitive paths. I think toLower should be removed.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requested, err := url.Parse(strings.ToLower(uri))
requested, err := url.Parse(uri)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, fixed it. (Had to add another fix, with the fix above test 8 would have failed).

Thanks for merging!

@raffis
Copy link
Contributor Author

raffis commented Mar 4, 2020

You rock, thank you for your contribution!

Thanks, same to you!

@aeneasr aeneasr merged commit 4104135 into ory:master Mar 4, 2020
@aeneasr
Copy link
Member

aeneasr commented Mar 4, 2020

I released a new tag for this so this can now be added to hydra

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

3 participants