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

fix(sso): use relative redirect URLs. Fixes #13031 #13747

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MasonM
Copy link
Contributor

@MasonM MasonM commented Oct 12, 2024

Fixes #13031

Motivation

When running Argo in plain text mode behind a TLS termination proxy with SSO enabled, you will always be redirected to the workflows page after logging in, regardless of which page you came from. This is happening because server/auth/sso/sso.go is using the scheme and host of the request to determine the redirect URL, which can be different than the original request when a proxy is involved.

Modifications

This is an alternative to #13609. @agilgur5 mentioned in #13609 (comment) that might be susceptible to open redirects. I can't think of any attack vector where that can happen that wasn't already a viable attack vector, but regardless, this side-steps the whole issue by switching the frontend to using relative redirect URLs (e.g. /workflows) instead of absolute URLs, which removes the need to verify the scheme and host of the URL.

Specifically, it uses what the WHATWG URL standard calls path-absolute-URL strings (which, despite the name, are actually relative URL). This is something that oauth2-proxy also supports, and I copied the validation logic and tests it uses to the backend:

oauth2-proxy is MIT licensed, which is compatible with Apache 2.0, so there shouldn't be any licensing concerns.

The validation logic is hairy because of subtleties with how browsers handle absolute URLs. The article Handling Relative URLs for Redirects / Forwards goes into more detail.

Verification

Testing instructions:

  1. Run make start UI_SECURE=true PROFILE=sso
  2. Visit https://localhost:8080/cluster-workflow-templates
  3. Click the "Login" button
  4. Click "Log in with Example"
  5. Click "Grant Access"
  6. Confirm you're returned to https://localhost:8080/cluster-workflow-templates
recording.online-video-cutter.com.mp4

When running Argo in plain text mode behind a TLS termination proxy with SSO
enabled, you will always be redirected to the workflows page after logging in,
regardless of which page you came from. This is happening because
`server/auth/sso/sso.go` is using the protocol and host of the request to
determine the redirect URL, which can be different than the original request
when a proxy is involved.

This switches the frontend to redirect using relative redirect URLs, e.g.
`/workflows`. Specifically, it uses what the [WHATWG URL
standard](https://url.spec.whatwg.org/#path-absolute-url-string) calls
`path-absolute-URL` strings (which, despite the name, are actually relative
URL). This is something that `oauth2-proxy` also supports, and I copied
the validation logic and tests it uses to the backend:
* https://github.com/oauth2-proxy/oauth2-proxy/blob/ab448cf38e7c1f0740b3cc2448284775e39d9661/pkg/app/redirect/validator.go#L14-L16
* https://github.com/oauth2-proxy/oauth2-proxy/blob/ab448cf38e7c1f0740b3cc2448284775e39d9661/pkg/app/redirect/validator.go#L47

`oauth2-proxy` is [MIT
licensed](https://github.com/oauth2-proxy/oauth2-proxy/blob/ab448cf38e7c1f0740b3cc2448284775e39d9661/LICENSE),
which is compatible with Apache 2.0, so there shouldn't be any licensing
concerns.

The validation logic is hairy because of subtleties with how browsers
handle absolute URLs. The article [Handling Relative URLs for Redirects
/ Forwards](https://nikola.dev/posts/2021-05-10/handling_relative_urls)
goes into more detail.

Signed-off-by: Mason Malone <[email protected]>
@agilgur5
Copy link

agilgur5 commented Oct 14, 2024

This is an alternative to #13609. @agilgur5 mentioned in #13609 (comment) that might be susceptible to open redirects. I can't think of any attack vector where that can happen that wasn't already a viable attack vector, but regardless, this side-steps the whole issue by switching the frontend to using relative redirect URLs (e.g. /workflows) instead of absolute URLs, which removes the need to verify the scheme and host of the URL.

I had thought about making the UI use relative URLs too to avoid open redirects entirely, which is something I've done in past jobs before too (~2015ish). I'm not sure if the previous UI logic was exploitable client-side (as in, other than server-side proxy discussed in the linked thread), but I did have a low priority todo to check that

So this approach ostensibly makes sense to me, but I need to carefully check the SSO code in particular

@MasonM MasonM changed the title fix(sso): use relative redirect URLs. Fixed #13031 fix(sso): use relative redirect URLs. Fixes #13031 Oct 15, 2024
@MasonM MasonM added the prioritized-review For members of the Sustainability Effort label Jan 4, 2025
@MasonM
Copy link
Contributor Author

MasonM commented Jan 9, 2025

/retest

@MasonM MasonM requested a review from Joibel January 10, 2025 05:12
@MasonM
Copy link
Contributor Author

MasonM commented Jan 10, 2025

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sso-rbac area/ui prioritized-review For members of the Sustainability Effort type/security Security related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect redirect after Login when terminating TLS with reverse proxy
2 participants