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

Whitelist domains #15

Merged
merged 8 commits into from Feb 2, 2019
Merged

Whitelist domains #15

merged 8 commits into from Feb 2, 2019

Conversation

JoelSpeed
Copy link
Member

@JoelSpeed JoelSpeed commented Jan 15, 2019

This PR replaces: bitly/oauth2_proxy#464
Fixes: #12

Description

Adds a whitelist-domain flag that can be used to whitelist a set of domains for the redirect parameter in the authentication request

Motivation and Context

I wrote this to fix #399.

It allows you to set a whitelist of redirect domains which is useful when you wish to run 1 copy of the oauth2_proxy but protect multiple different endpoints (used particularly in the nginx auth_request mode)

How Has This Been Tested?

This has been running for us in production for nearly a year.

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

@danihodovic
Copy link

Doesn't the cookie-domains option already allow you to do this? What is the difference?

@JoelSpeed
Copy link
Member Author

Doesn't the cookie-domains option already allow you to do this? What is the difference?

It does not. There is a security check in place as part of any OAuth2 flow that you should have a predefined list of approved "redirect URLs". The initial request to the OAuth2 Proxy will have an rd query parameter that tells the proxy where to redirect to after it has completed the authentication flow.

This PR allows you to set the redirect URL to be on a different domain than the OAuth2 proxy is hosted. With the current behaviour, if I have the OAuth2 proxy hosted at auth.example.com and my app at app.example.com, then I would want ?rd=app.example.com/some/page but the OAuth2 proxy expects to be on the same domain and so would replace this with ?rd=/ and redirect back to auth.example.com once the authentication flow is completed.

As I say, it is standard to be able to redirect to a different domain as part of OAuth2 but there has to be a validated list, which is what we are implementing in this PR.

As for the cookie domain, that is only used when returning the Set-Cookie header, arguably we could leverage this flag to guess the redirects but that is less flexible, if cookie-domain: .example.com then we would have to allow redirects to any subdomain of example.com, which may not be desired, with this approach we can set whitelist-domains: foo.example.com, bar.example.com and only allow the separate proxy to protect those two subdomains.

Does that answer your question @danihodovic?

@danihodovic
Copy link

danihodovic commented Jan 16, 2019

Yes, thanks! 👍 I've worked around this problem by having example.com as a sort of index page for the internal tools and set cookie domain to cookie-domain = .example.com, but your solution looks more elegant.

@Miouge1
Copy link
Contributor

Miouge1 commented Jan 23, 2019

This is great! It's one of the most popular PR in the bitly project, I'm looking forward to see this in push/oauth2_proxy.

Copy link
Member

@loshz loshz left a comment

Choose a reason for hiding this comment

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

LGTM once conflicts are fixed :)

@jaybe78
Copy link

jaybe78 commented Feb 2, 2019

Hey @JoelSpeed ,

I've tested the branch. It works so good! Thanks for the great job.
Will this be merged anytime soon ?

Thx

@JoelSpeed
Copy link
Member Author

I was just waiting on a sanity check after my rebase but since the tests didn't break I don't think I've changed the behaviour, which is good to know 😅

I'll get this merged shortly

@JoelSpeed
Copy link
Member Author

@syscll Got a moment to re-approve this? Pushing to the branch dismissed the review

Copy link
Member

@loshz loshz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@JoelSpeed JoelSpeed merged commit fa25456 into master Feb 2, 2019
@JoelSpeed JoelSpeed deleted the whitelist-domains branch February 4, 2019 11:19
@Miouge1
Copy link
Contributor

Miouge1 commented Feb 6, 2019

I would love to see this released in 3.1.0 :)

@JoelSpeed
Copy link
Member Author

My current plan is to get #16 wrapped up and then cut a new release at that point, hopefully within the next week or so 😄

@Miouge1
Copy link
Contributor

Miouge1 commented Feb 25, 2019

3.1.0 is now release with white-list domain support. Well done everyone 🎉 !

@ghostsquad
Copy link

The rd= parameter is not really explained anywhere. I'd like to know what's the best way to allow redirecting to arbitrary subdomains.

michael-freidgeim-webjet pushed a commit to MNF/oauth2-proxy that referenced this pull request Sep 4, 2021
added th new packages AI web path
vjacynycz pushed a commit to vjacynycz/oauth2-proxy that referenced this pull request Jul 19, 2022
* Fix vulnerabilities
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.

Possible to use "Dynamic" callback URL?
6 participants