mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-29 15:15:27 -07:00
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:
@@ -15,17 +15,32 @@ const PLATFORM_ALIAS: Record<string, string> = {
|
|||||||
windows: 'windows',
|
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(
|
export async function GET(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: Promise<{ platform: string }> },
|
{ params }: { params: Promise<{ platform: string }> },
|
||||||
) {
|
) {
|
||||||
|
const origin = getPublicOrigin(request);
|
||||||
const { platform } = await params;
|
const { platform } = await params;
|
||||||
// No prebuilt Linux binary yet — send straight to the build-from-source page.
|
// No prebuilt Linux binary yet — send straight to the build-from-source page.
|
||||||
if (platform === 'linux') {
|
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 normalized = PLATFORM_ALIAS[platform];
|
||||||
const target = new URL('/download', request.url);
|
const target = new URL('/download', origin);
|
||||||
if (normalized) target.searchParams.set('platform', normalized);
|
if (normalized) target.searchParams.set('platform', normalized);
|
||||||
return NextResponse.redirect(target, 307);
|
return NextResponse.redirect(target, 307);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user