Gateway: harden trusted proxy X-Forwarded-For parsing (#22429)

This commit is contained in:
Vincent Koc
2026-02-20 23:59:20 -05:00
committed by GitHub
parent 35be87b09b
commit 07039dc089
3 changed files with 16 additions and 2 deletions

View File

@@ -147,7 +147,11 @@ function stripOptionalPort(ip: string): string {
}
export function parseForwardedForClientIp(forwardedFor?: string): string | undefined {
const raw = forwardedFor?.split(",")[0]?.trim();
const entries = forwardedFor
?.split(",")
.map((entry) => entry.trim())
.filter((entry) => entry.length > 0);
const raw = entries?.at(-1);
if (!raw) {
return undefined;
}