Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`client-ip` is not an IP address when `x-forwarded-for` holds a list or a port

Abierto Apto para principiantes
#8,532 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Dev-next-gen ya está trabajando en esto.

Desde el 27/9/2026.

  • #8533 de @Dev-next-gen — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
backend, cli

Línea de trabajo

Empieza en src/lib/functions/server.ts, en createHandler, y compara después el manejo de requests circundante con src/utils/proxy.ts. Ejecuta la reproducción del issue con functions:serve usando ambos ejemplos de x-forwarded-for. Se considera terminado cuando client-ip y x-nf-client-connection-ip contienen una IP válida para esas entradas, mientras netlify dev no se ve afectado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

Under netlify functions:serve, the client-ip and x-nf-client-connection-ip headers that
reach a serverless function are not always an IP address. They can be the whole
x-forwarded-for list, or a port number.

createHandler builds the value like this (src/lib/functions/server.ts):

let remoteAddress = request.header('x-forwarded-for') || request.connection.remoteAddress || ''
remoteAddress = remoteAddress.split(remoteAddress.includes('.') ? ':' : ',').pop()?.trim() ?? ''

The separator is chosen from whether the string contains a dot, so a comma-separated IPv4 list
is never split on the comma.

Steps to reproduce
mkdir -p netlify/functions
cat > netlify/functions/whoami.js <<'EOF'
exports.handler = async (event) => ({
  statusCode: 200,
  body: JSON.stringify({ clientIp: event.headers['client-ip'] }),
})
EOF

netlify functions:serve --port 9999 &
curl -s -H 'x-forwarded-for: 1.2.3.4, 5.6.7.8' localhost:9999/.netlify/functions/whoami
curl -s -H 'x-forwarded-for: 1.2.3.4:5678'     localhost:9999/.netlify/functions/whoami
Expected behavior

One IP address, i.e. net.isIP(clientIp) !== 0.

Actual behavior
{"clientIp":"1.2.3.4, 5.6.7.8"}
{"clientIp":"5678"}

net.isIP() returns 0 for both. A function that parses client-ip, compares it, or
passes it to a geo/rate-limit library gets a value that cannot be an address, and this
only shows up locally — in production Netlify sends a single address.

Note that netlify dev is unaffected: the dev proxy overwrites x-forwarded-for with
req.connection.remoteAddress before the functions server sees it
(src/utils/proxy.ts), so a single address always arrives. functions:serve runs the
functions server without that proxy, so the client's own header is used verbatim.

Environment
  • netlify-cli 27.10.0 (main at 904515c)
  • Node 22.23.3
Lenguaje dominante
TypeScript
Estrellas
1.9k
Forks
480
Merge medio
1 d 15 h
PR fusionados (30 d)
66

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de netlify/cli

Todos los issues de netlify/cli

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.