fix: use rightmost XFF entry in rate limiter to prevent IP spoofing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
fuomag9
2026-02-25 09:25:34 +01:00
parent 0758e5b27a
commit 5d219095b3
2 changed files with 4 additions and 2 deletions

View File

@@ -12,7 +12,8 @@ function getClientIp(request: NextRequest): string {
// In production, ensure your reverse proxy (Caddy) sets these headers correctly
const forwarded = request.headers.get("x-forwarded-for");
if (forwarded) {
return forwarded.split(",")[0]?.trim() || "unknown";
const parts = forwarded.split(",");
return parts[parts.length - 1]?.trim() || "unknown";
}
const real = request.headers.get("x-real-ip");
if (real) {