Skip to content

Commit 62be29f

Browse files
committed
fix: issue with using BASE_URL and links
1 parent e2eb7ca commit 62be29f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/webui.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,24 @@ export function configure(app: express.Application) {
129129
// Example original URL (untrusted): https://foo.fileset.com/bar/.
130130
const currentUrl = new URL(`${req.protocol}://${host}${req.originalUrl}`);
131131
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+
}
132144
// Verify the `?returnTo` and `state` parameters are not external URLs.
133145
// Subdomains (i.e. staging environment URLs) are permitted, as they are
134146
// trusted.
135147
if (!originalUrl.host.endsWith(currentUrl.host)) {
136148
res.status(400);
149+
res.contentType('text/plain');
137150
res.send('External redirects are disallowed.');
138151
return;
139152
}

0 commit comments

Comments
 (0)