Skip to content

Commit d478e06

Browse files
committed
Parse xff properly
1 parent 5811ab8 commit d478e06

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

apps/webapp/app/routes/login.magic/route.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export async function action({ request }: ActionFunctionArgs) {
105105
}
106106

107107
const { email } = data;
108-
const clientIp = request.headers.get("x-forwarded-for");
108+
const xff = request.headers.get("x-forwarded-for");
109+
const clientIp = extractClientIp(xff);
109110

110111
const [error] = await tryCatch(
111112
Promise.all([
@@ -168,6 +169,13 @@ export async function action({ request }: ActionFunctionArgs) {
168169
}
169170
}
170171

172+
const extractClientIp = (xff: string | null) => {
173+
if (!xff) return null;
174+
175+
const parts = xff.split(",").map((p) => p.trim());
176+
return parts[parts.length - 1]; // take last item, ALB appends the real client IP by default
177+
};
178+
171179
export default function LoginMagicLinkPage() {
172180
const { magicLinkSent, magicLinkError } = useTypedLoaderData<typeof loader>();
173181
const navigate = useNavigation();

0 commit comments

Comments
 (0)