@@ -34,7 +34,7 @@ export const LoginPage: FC = () => {
34
34
let redirectUrl : URL | null = null ;
35
35
try {
36
36
redirectUrl = new URL ( redirectTo ) ;
37
- } catch ( err ) {
37
+ } catch {
38
38
// Do nothing
39
39
}
40
40
@@ -62,6 +62,7 @@ export const LoginPage: FC = () => {
62
62
}
63
63
64
64
const regions = regionsQuery . data . regions ;
65
+ // Process path app urls. They're in the form of https://dev.coder.com/test
65
66
const pathUrls = regions
66
67
? regions
67
68
. map ( ( region ) => {
@@ -73,6 +74,7 @@ export const LoginPage: FC = () => {
73
74
} )
74
75
. filter ( ( url ) => url !== null )
75
76
: [ ] ;
77
+ // Process wildcard hostnames. They're in the form of `*.apps.dev.coder.com`.
76
78
const wildcardHostnames = regions
77
79
? regions
78
80
. map ( ( region ) => region . wildcard_hostname )
@@ -81,12 +83,14 @@ export const LoginPage: FC = () => {
81
83
. map ( ( hostname ) => hostname . slice ( 1 ) )
82
84
: [ ] ;
83
85
86
+ // Ensure the redirect url matches one of the allowed options.
84
87
const allowed =
88
+ // For path URLs ensure just the hosts match.
85
89
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.
90
94
isApiRoute ;
91
95
92
96
if ( allowed ) {
0 commit comments