Skip to content

Commit b1b1a3b

Browse files
committed
fixup! fix: login redirect
1 parent cc25e09 commit b1b1a3b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

site/src/pages/LoginPage/LoginPage.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const LoginPage: FC = () => {
3434
let redirectUrl: URL | null = null;
3535
try {
3636
redirectUrl = new URL(redirectTo);
37-
} catch (err) {
37+
} catch {
3838
// Do nothing
3939
}
4040

@@ -62,6 +62,7 @@ export const LoginPage: FC = () => {
6262
}
6363

6464
const regions = regionsQuery.data.regions;
65+
// Process path app urls. They're in the form of https://dev.coder.com/test
6566
const pathUrls = regions
6667
? regions
6768
.map((region) => {
@@ -73,6 +74,7 @@ export const LoginPage: FC = () => {
7374
})
7475
.filter((url) => url !== null)
7576
: [];
77+
// Process wildcard hostnames. They're in the form of `*.apps.dev.coder.com`.
7678
const wildcardHostnames = regions
7779
? regions
7880
.map((region) => region.wildcard_hostname)
@@ -81,12 +83,14 @@ export const LoginPage: FC = () => {
8183
.map((hostname) => hostname.slice(1))
8284
: [];
8385

86+
// Ensure the redirect url matches one of the allowed options.
8487
const allowed =
88+
// For path URLs ensure just the hosts match.
8589
pathUrls.some((url) => url.host === window.location.host) ||
86-
wildcardHostnames.some((wildcard) =>
87-
window.location.host.endsWith(wildcard),
88-
) ||
89-
// api routes need to be manually set with href
90+
// For wildcards, ensure just the suffixes match.
91+
wildcardHostnames.some((wildcard) => redirectTo.endsWith(wildcard)) ||
92+
// API routes need to be manually set with href, since react's
93+
// navigate will keep us within the SPA.
9094
isApiRoute;
9195

9296
if (allowed) {

0 commit comments

Comments
 (0)