Skip to content

Commit 876ccda

Browse files
committed
fix(proxy): validate host against allowlist to prevent open redirect (fixes #65)
1 parent 8f46915 commit 876ccda

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

apps/logicsrc-web/src/proxy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type { NextRequest } from "next/server";
44
// Canonical host: 301 www.* to the bare apex domain over https, preserving
55
// path + query (e.g. https://www.logicsrc.com/foo -> https://logicsrc.com/foo).
66
// This is the Next 16 "proxy" (formerly middleware) entrypoint.
7+
const ALLOWED_APEX = process.env.PUBLIC_DOMAIN || "logicsrc.com";
8+
79
export function proxy(request: NextRequest): NextResponse {
810
const host = request.headers.get("host") ?? "";
9-
if (host.startsWith("www.")) {
10-
const apexHost = host.slice("www.".length);
11+
if (host === `www.${ALLOWED_APEX}`) {
1112
const { pathname, search } = request.nextUrl;
12-
return NextResponse.redirect(`https://${apexHost}${pathname}${search}`, 301);
13+
return NextResponse.redirect(`https://${ALLOWED_APEX}${pathname}${search}`, 301);
1314
}
1415
return NextResponse.next();
1516
}

0 commit comments

Comments
 (0)