8000 fix(site): sanitize login redirect by coadler · Pull Request #15208 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix(site): sanitize login redirect #15208

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

Merged
merged 10 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! fix: login redirect
  • Loading branch information
coadler committed Oct 23, 2024
commit 237d292a9f66539c19109d85370bfec1d3ad1702
8 changes: 2 additions & 6 deletions site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export const LoginPage: FC = () => {
}

const isApiRouteRedirect = redirectTo.startsWith("/api/v2");
const isReactRedirect =
(!redirectUrl ||
(redirectUrl && redirectUrl.host === window.location.host)) &&
!isApiRouteRedirect;

useEffect(() => {
if (!buildInfoQuery.data || isSignedIn) {
Expand All @@ -53,12 +49,12 @@ export const LoginPage: FC = () => {
});
}, [isSignedIn, buildInfoQuery.data, user?.id]);

if (isSignedIn && !isReactRedirect) {
if (isSignedIn && isApiRouteRedirect) {
const sanitizedUrl = new URL(redirectTo, window.location.origin);
Copy link
Member

Choose a reason for hiding this comment

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

This does not work for subdomain apps though right? If they are on another domain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're not on another domain. The redirect from a workspace proxy subdomain app is to /api/v2/applications/auth-redirect. The redirect sanitization happens there.

Copy link
Member

Choose a reason for hiding this comment

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

I'll trust you 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could be wrong but that's what I always noticed in my testing.

window.location.href = sanitizedUrl.pathname + sanitizedUrl.search;
return null;
}
if (isSignedIn && isReactRedirect) {
if (isSignedIn && !isApiRouteRedirect) {
return (
<Navigate to={redirectUrl ? redirectUrl.pathname : redirectTo} replace />
Copy link
Member

Choose a reason for hiding this comment

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

So I poked around a bit more of the code, and I'm just making sure: there's a second file that calls the retrieveRedirect function (LoginPageView.tsx). Do we need to update anything around that?

Because right now, the control flow is set up so that the component:

  1. Gets the redirectTo value from the search param's redirect param
  2. Passes it to the SignInForm
  3. Passes that to the OAuthSignInForm
  4. As long as GitHub is enabled as an auth method, a button shows up with an href that uses the raw redirectTo as a param

Not sure how the callback logic works, but would the updates to this file catch any issues from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good find. This is being sent directly to the backend which handles approving the redirect URLs, so it doesn't need any validation from the frontend.

);
Expand Down
Loading
0