File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -129,11 +129,24 @@ export function configure(app: express.Application) {
129
129
// Example original URL (untrusted): https://foo.fileset.com/bar/.
130
130
const currentUrl = new URL ( `${ req . protocol } ://${ host } ${ req . originalUrl } ` ) ;
131
131
const originalUrl = new URL ( req . query . state as string ) ;
132
+ // If using the `FILESET_BASE_URL` feature, which allows for custom hostnames, replace
133
+ // the App Engine `-dot-` hostname with the `BASE_URL` hostname and redirect.
134
+ const defaultHostnamePart = `fileset-dot-${ process . env . GOOGLE_CLOUD_PROJECT } .appspot.com` ;
135
+ if (
136
+ originalUrl . host . includes ( defaultHostnamePart ) &&
137
+ process . env . FILESET_BASE_URL
138
+ ) {
139
+ originalUrl . host = originalUrl . host . replace (
140
+ defaultHostnamePart ,
141
+ process . env . FILESET_BASE_URL
142
+ ) ;
143
+ }
132
144
// Verify the `?returnTo` and `state` parameters are not external URLs.
133
145
// Subdomains (i.e. staging environment URLs) are permitted, as they are
134
146
// trusted.
135
147
if ( ! originalUrl . host . endsWith ( currentUrl . host ) ) {
136
148
res . status ( 400 ) ;
149
+ res . contentType ( 'text/plain' ) ;
137
150
res . send ( 'External redirects are disallowed.' ) ;
138
151
return ;
139
152
}
You can’t perform that action at this time.
0 commit comments