fix(landing): use public origin for download redirects behind proxies (#498)

Prefer x-forwarded host/proto for redirect URL construction so users are not sent to internal localhost origins.

Fixes #496
This commit is contained in:
Shekhar Kumar
2026-04-19 15:57:58 -07:00
committed by GitHub
parent 27a5a62581
commit e3f7cd9d00
+17 -2
View File
@@ -15,17 +15,32 @@ const PLATFORM_ALIAS: Record<string, string> = {
windows: 'windows',
};
function getPublicOrigin(request: NextRequest): string {
const forwardedHost = request.headers.get('x-forwarded-host');
const forwardedProto = request.headers.get('x-forwarded-proto');
if (forwardedHost && forwardedProto) {
// Behind reverse proxies/CDNs, request.url can be an internal origin
// (for example localhost:8080). Prefer forwarded headers so redirects
// keep users on the public domain.
return `${forwardedProto}://${forwardedHost}`;
}
return new URL(request.url).origin;
}
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ platform: string }> },
) {
const origin = getPublicOrigin(request);
const { platform } = await params;
// No prebuilt Linux binary yet — send straight to the build-from-source page.
if (platform === 'linux') {
return NextResponse.redirect(new URL('/linux-install', request.url), 307);
return NextResponse.redirect(new URL('/linux-install', origin), 307);
}
const normalized = PLATFORM_ALIAS[platform];
const target = new URL('/download', request.url);
const target = new URL('/download', origin);
if (normalized) target.searchParams.set('platform', normalized);
return NextResponse.redirect(target, 307);
}